当超过两行时如何纠正 ConstraintLayout TextView 重叠

2024-04-12

我遇到约束布局问题,其中一个文本视图中到达第二行的文本不会向下推被限制在其下方的另一个文本视图,直到该行的中间。

我用三个文本视图构建了一个简单的布局。第一个文本视图位于左侧并具有设定的宽度。第二个位于它的右侧,位于它与其父级之间。第三个位于第二个下方,第一个左侧。

I want it to look like: Layout of activity with the three text views as desired

However if I remove the text "Not Overlapping." I get: Layout of activity with the third text view overlapping the second.

The point at which it changes (The "O" in "Not Overlapping")appears to be when the length of the text fills two lines when the first Text View is not there: Image showing if the first TextView was not there that the text would wrap perfectly.

那么如何更改此布局,以便即使我在屏幕左侧有一个文本视图,它也会在文本视图 3 到达两行时将其向下推?而不是将其推到第二行的一半。

My XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context="com.testapp.myapplication.MainActivity">

    <TextView
        android:id="@+id/text_view_1"
        android:layout_width="120dp"
        android:layout_height="0dp"
        android:background="@color/colorAccent"
        android:text="Text View 1"
        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/text_view_2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:background="#22AA99"
        android:text="Text View 2 Showing problem with overlap. Overlapping. Not O"
        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
        app:layout_constraintLeft_toRightOf="@id/text_view_1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <TextView
        android:id="@+id/text_view_3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#FF00FF"
        android:text="Text View 3"
        android:textAppearance="@style/TextAppearance.AppCompat.Body2"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@id/text_view_1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/text_view_2" />

</android.support.constraint.ConstraintLayout>

Thanks.


我从此发现

app:layout_constrainedHeight="true"

从约束布局1.1.0-beta2 https://androidstudio.googleblog.com/2017/10/constraintlayout-110-beta-2.html对wrap_content 施加约束。因此,我觉得这是正确的解决方案,因为这也允许我设置app:layout_constraintBottom_toBottomOf="parent"这会在视图底部启用边距。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

当超过两行时如何纠正 ConstraintLayout TextView 重叠 的相关文章

随机推荐

  • 如何使用 LINQ 从没有主键的表中插入/更新/删除记录

    我正在使用 LINQ 连接到第三者数据库 现在我必须将一些记录插入到没有设置主键的表中 并且出现以下异常 System InvalidOperationException 无法对 表 the table 执行创建 更新或删除操作 因为它没有
  • 如何在不使用 Next() 的情况下获取 sql.Rows 的计数?

    我需要得到的长度 sql Rows before我开始 Next 循环来获取值 一种方法是通过循环 Next 两次来创建行切片 获取计数 然后循环该新切片以提取值 但这似乎效率很低 所以我希望有一种更好的方法做这个 查看文档 我没有看到任何
  • mclapply 遇到取决于核心 id 的错误?

    我有一组基因 我需要并行计算一些系数 系数在里面计算GeneTo GeneCoeffs filtered它将基因名称作为输入并返回 2 个数据框的列表 长度为 100gene array我使用不同数量的核心运行此命令 5 6 和 7 Coe
  • 从字符串中获取“$#”的所有正则表达式匹配项

    我有一个字符串 其中包含多个美元符号实例 后跟一个正数 我需要使用正则表达式获取每个实例 这是一个字符串的示例 This that 1 who 2 到目前为止 我使用 vb net 得到的结果如下 Dim wordSplitMatches
  • npm ci 命令失败并显示“无法读取未定义的属性‘@angular/animations’”

    在为我的 Angular 项目执行 docker build 时 在npm ci步骤 我收到以下错误 Cannot read property angular animations of undefined 由于没有正确的错误 我们无法找到
  • 重复AlarmManager如何启动AsyncTask?

    我通常编写这段代码来启动服务AlarmManager intent new Intent getActivity someservice class pendingNotificationIntent PendingIntent getSe
  • 在位图上绘制长字符串会导致绘图问题

    我正在将一个长字符串绘制到位图 超过一百万个字符 包括多行字符 r n 由一个写StringBuilder 我的文本转位图代码如下 public static Bitmap GetBitmap string input Font input
  • 是否可以以编程方式抛出 NullPointerException? [关闭]

    Closed 这个问题是基于意见的 help closed questions 目前不接受答案 当有后置条件 方法的返回值不能为null时 怎么办 我可以 assert returnValue null Not acceptable nul
  • 防病毒软件将 python.exe 检测为 idp.generic?

    我开始学习Python 安装了 python 2 7 和 Pycharm 当我在 Pycharm 中打开 python 控制台时 我的防病毒软件警告我路径中的 python exevenv Scripts被感染IDP Generic 以前有
  • SDL 2.0源码中有1.3吗?

    我正在研究 SDL 2 0 源代码 注意到其中有另一个声称是 1 3 版本的 SDL 文件夹 我对它很感兴趣 因为它有 android iphone 和其他一些的源代码 稳定版本 1 2 似乎有很大不同 我的问题是这样的 SDL 维基链接
  • 基于原型的 OO 与基于类的 OO 相比有哪些优点?

    为什么基于类的 OO 如此受欢迎 而不是基于原型的 OO 他们在学校教授后者吗 尽管 Javascript 是基于原型的 但大多数人主要是在功能上使用它 或者通过尝试模拟基于类的系统的框架 我知道Sun已经做了一些研究Self http r
  • 游戏开发者的 Flash 性能:本机渲染 VS BitmapData 帧缓冲区

    我开发了一款 2D 射击游戏很多物体 and 激进的滚动 问题 哪种方式更好 选择 1 使用原生 Flash 渲染 从 Bitmap 派生游戏对象 使用现有的 x y 宽度 高度 bitmapData 将所有对象添加为子 UI Compon
  • Win7 上的 ASP.Net 中的 EventLog 权限失败

    我有一个 ASP Net 应用程序 net 3 5 SP1 在 Win7 中运行 在登录过程中 ASP Net 登录控件中的某些内容导致写入事件日志中的安全日志 这听起来对我来说可以接受 问题是该应用程序似乎没有执行此操作的权限 有错误的是
  • LINQ 结果在 for 循环结束时发生变化

    当对数据源执行一组 LINQ 查询时 我使用的是 LINQ to SQL 但这里也只使用List
  • 如何将 docx 转换为 json 以用于 firebase

    我在 Docx 中存储了引号 但我想将其转换为 JSON 因此我不必在 firebase 中手动添加每个单独的引号 这里是 file 这是我的数据库的样子以及我想如何在 firebase 中存储报价的 SS 现在 如何将 docx 文件转换
  • 未捕获的错误:没有模块:用户 Angularjs

    这是这个的后续问题如何使用rails服务器在Angular中获取索引数据 https stackoverflow com questions 18312689 how to fetch index data in angular using
  • Python,在我的 python 代码中出现了意外的关键字参数 [关闭]

    Closed 这个问题是无法重现或由拼写错误引起 help closed questions 目前不接受答案 我的 python 代码一直给我这个错误 这是我尝试调用的函数 其下面是调用它的代码 from sys import stdout
  • 等待异步函数在地图内完成

    考虑以下简单的代码 await Promise all arrayOfObjects map async obj gt return await someAsyncFunctionOnObj obj 我的问题是 对象数组 and 对象上的一
  • cocos2d中的水效果

    我想在我的应用程序的背景层上有水效果 该效果不需要对触摸或任何东西做出反应 它只需要稍微晃动图像即可 CCWaves3D 看起来不错 但当我运行它时 边缘周围留下了令人讨厌的黑色伪影 类似CCShaky3D CCLiquid 将我的应用程序
  • 当超过两行时如何纠正 ConstraintLayout TextView 重叠

    我遇到约束布局问题 其中一个文本视图中到达第二行的文本不会向下推被限制在其下方的另一个文本视图 直到该行的中间 我用三个文本视图构建了一个简单的布局 第一个文本视图位于左侧并具有设定的宽度 第二个位于它的右侧 位于它与其父级之间 第三个位于