
我也试图限制它们的大小,但是在有两个小文本和一个非常大的文本的情况下,即使布局仍然留有一些空间,大的文本也将被椭圆化.
样本布局:
<?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="match_parent" androID:background="@androID:color/white" androID:padding="22dp"> <TextVIEw androID:ID="@+ID/greenTextVIEw" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_marginEnd="8dp" androID:ellipsize="end" androID:maxlines="1" androID:textcolor="@androID:color/holo_green_dark" app:layout_constraineDWIDth="true" app:layout_constraintEnd_toStartOf="@ID/blueTextVIEw" app:layout_constraintHorizontal_bias="0.0" app:layout_constraintHorizontal_chainStyle="packed" app:layout_constraintStart_toStartOf="parent" app:layout_constrainttop_totopOf="parent" tools:text="TextVIEw" /> <TextVIEw androID:ID="@+ID/blueTextVIEw" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_marginEnd="8dp" androID:ellipsize="end" androID:maxlines="1" androID:textcolor="@androID:color/holo_blue_dark" app:layout_constraineDWIDth="true" app:layout_constraintBaseline_toBaselineOf="@ID/greenTextVIEw" app:layout_constraintEnd_toStartOf="@ID/orangetextVIEw" app:layout_constraintStart_toEndOf="@ID/greenTextVIEw" tools:text="Another TextVIEw " /> <TextVIEw androID:ID="@+ID/orangetextVIEw" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_marginEnd="8dp" androID:ellipsize="end" androID:maxlines="1" androID:textcolor="@androID:color/holo_orange_dark" app:layout_constraineDWIDth="true" app:layout_constraintBaseline_toBaselineOf="@ID/blueTextVIEw" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toEndOf="@ID/blueTextVIEw" tools:text="Another TextVIEw" /> </androID.support.constraint.ConstraintLayout>
这些是使用样本布局的一些情况
没有TextVIEws是椭圆化的:
第一个TextVIEw是椭圆化:
最后一个TextVIEw没有椭圆化并将其他文件推出屏幕:
这些是一些未涵盖所有案例的可能解决方案
使用androID:maxWIDth =“90dp”来阻止TextVIEw增长,但也不必要地限制文本:
使用androID:layout_wIDth =“0dp”启用“match_constraint”也不是最佳解决方案,因为布局将为每个TextVIEw保留三分之一的显示宽度,即使文本小于:
解决方法 使用FlexBox<com.Google.androID.flexBox.FlexBoxLayout 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="wrap_content" app:layout_constrainttop_totopOf="parent" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:alignContent="flex_start" app:alignItems="flex_start" app:flexWrap="nowrap" app:divIDerDrawable="@drawable/ic_divIDer" app:showdivIDer="mIDdle"> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:maxlines="1" androID:textSize="18sp" app:layout_minWIDth="50dp" androID:textcolor="@androID:color/holo_green_dark" androID:ellipsize="end" androID:text="Text VIEw"/> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:maxlines="1" androID:ellipsize="end" androID:textcolor="@androID:color/holo_blue_dark" androID:textSize="18sp" app:layout_minWIDth="50dp" androID:text="Another TextVIEw"/> <TextVIEw androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:maxlines="1" androID:textcolor="@androID:color/holo_orange_dark" androID:textSize="18sp" app:layout_minWIDth="50dp" androID:ellipsize="end" androID:text="Another TextVIEw"/></com.Google.androID.flexBox.FlexBoxLayout>
此布局的输出:
总结以上是内存溢出为你收集整理的android – 如何使用ConstraintLayout水平对齐三个TextView全部内容,希望文章能够帮你解决android – 如何使用ConstraintLayout水平对齐三个TextView所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)