android - 带有约束布局的 TextView 走出屏幕
问题描述
我正在使用ConstraintLayout
在我的应用程序中创建以下 xml。如您所见,我的第一项很好,但是在第二项中,我textView
的某些部分不在屏幕上!
这是我的XML
代码:
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/ly_user"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
app:layout_constraintRight_toRightOf="parent"
android:id="@+id/im_user_icon"
android:layout_width="@dimen/default_message_icon_size"
android:layout_height="@dimen/default_message_icon_size"
android:src="@drawable/user_pacific"/>
<ImageView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/im_user_icon"
android:id="@+id/im_user_arrow"
android:layout_width="30dp"
android:layout_height="30dp"
android:src="@drawable/arrow_bg1"/>
<View
android:id="@+id/view_user_guidLine"
android:layout_width="1dp"
android:layout_height="0dp"
app:layout_constraintLeft_toLeftOf="@id/im_user_arrow"
app:layout_constraintRight_toRightOf="@id/im_user_arrow"/>
<TextView
app:layout_constraintTop_toBottomOf="@+id/im_user_icon"
app:layout_constraintRight_toLeftOf="@+id/view_user_guidLine"
android:id="@+id/tv_user_message"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="right"
android:padding="8dp"
android:minWidth="@dimen/default_message_textarea_width"
android:minHeight="@dimen/default_message_textarea_height"
android:background="@drawable/bg_right_text"
android:textColor="@android:color/white"/>
</android.support.constraint.ConstraintLayout>
我知道我可以解决这个问题,将下面的行添加到textView
, 但我需要我textView
的wrapContent
。
app:layout_constraintLeft_toLeftOf="parent"
解决方案
您可以将TextView's
宽度设置为wrap_content
,但为了防止它扩展到屏幕之外,您还需要添加左侧约束并app:layout_constrainedWidth="true"
用于强制约束。
现在,要使TextView
棒向右,您需要添加app:layout_constraintHorizontal_bias="1"
,这将使其与右侧约束对齐。
总而言之,这些是所需的更改TextView
:
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="1"
android:layout_width="wrap_content"
推荐阅读
- c++17 - 将整数参数传递给接受浮点数的可变参数模板
- c# - 如何判断 C# 项目是否正在使用 SSD 构建?
- r - 如何为 r 文本分析创建定制的贸易/法律词典
- css - CSS 关键帧动画在 Chrome 和 Firefox 中停止工作
- excel - *EXCEL* 如果一系列单元格包含 *STRING*,则从正单元格中提取十进制数的总和
- php - 如何从 HTML/PHP 页面打印 png/jpg 文件?
- c# - 通过 csproj 文件中的 PackageReference 更新 nuget 包
- r - 忽略 x-label 对齐与拼凑而成的多个图:这可能吗?
- node.js - 在node.js中的回调中带有等待的递归函数
- android-studio - 在颤动中将文件添加到git忽略