android - 防止TextView在ConstraintLayout中与另一个重叠?
问题描述
我遇到了"Den Dolder"
TextView 总是与日期 TextView 重叠的问题。我尝试过使用app:layout_constraintRight_toLeftOf="@id/date_txtView"
,但令人惊讶的是没有效果!
没关系:
这不行:
解决方案
简短的解决方案:
尝试将app:layout_constraintHorizontal_weight="1"
和添加android:layout_width="0dp"
到您的两个 textViews - 它们在布局中都将采用相同的宽度。
更复杂布局的另一种解决方案:
你需要告诉你的两个文本视图的宽度都是0dp
,所以如果文本太长,它们会掉一行。
例如,在您的 2 个 textView 之间设置一个链,如下所示:
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
app:layout_constraintEnd_toStartOf="@+id/textView4"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView4"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="TextView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
它看起来像这样(没有 textView 与另一个重叠,它们只是下拉一行):
推荐阅读
- vue.js - 渲染新的 Vue 道具值
- javascript - 常规函数与箭头函数中的“this”范围
- artificial-intelligence - 有没有一种方法可以从运行在虚幻引擎上的游戏中访问游戏时间变量,例如健康条和其他分数
- ios - 由于 pod unity-iphone-framework.sh 第 42 行,xcode 构建未编译来源:未绑定变量
- javascript - Spark AR - 无法使用 Scene.create() 方法创建场景对象
- c# - 您在哪里使用 .NET Core 将 ViewModel 存储在 MVC 中?
- java - 当我尝试返回具体对象时,泛型代码不起作用
- javascript - 有没有办法在 eventdrop 上更改 fullcalender 版本 5.9.0 中的日期时间格式
- swift - 尝试将项目提交到 App Store 后出现 MDFInternationalization 错误
- python - Python 正则表达式提取电子邮件信息