Android 将一组视图与屏幕右侧显示的最大视图的右侧对齐

Android 将一组视图与屏幕右侧显示的最大视图的右侧对齐,android,android-linearlayout,android-view,android-constraintlayout,Android,Android Linearlayout,Android View,Android Constraintlayout,我可以使用ConstraintLayout创建一个视图,根据最大的子视图将子视图与对齐吗? 示例: 考虑到其中一行中打印的右侧文本可以更大,我希望将进度条与右侧最大的文本对齐。 可能吗?我可以用嵌套的LinearLayout来做,但我想知道ConstraintLayout是否能解决这个问题用start方向创建一个屏障,并引用右侧文本视图的所有ID。将每个进度条的结束约束到屏障。屏障将与最长的文本视图的开头对齐 如何实现这一点的示例XML: <?xml version="1.0" enco

我可以使用
ConstraintLayout
创建一个视图,根据最大的子视图将子视图与对齐吗?
示例:

考虑到其中一行中打印的右侧
文本可以更大,我希望将进度条与右侧最大的
文本对齐。

可能吗?我可以用嵌套的
LinearLayout
来做,但我想知道
ConstraintLayout
是否能解决这个问题

start
方向创建一个
屏障
,并引用右侧
文本视图
的所有ID。将每个进度条的
结束
约束到
屏障
屏障
将与最长的
文本视图
的开头对齐

如何实现这一点的示例XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">

    <androidx.constraintlayout.widget.Barrier
            android:id="@+id/barrier"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:barrierDirection="start"
            app:constraint_referenced_ids="text1,text2"/>

    <TextView
            android:id="@+id/progress1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ProgressBar"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toStartOf="@id/barrier" />

    <TextView
            android:id="@+id/progress2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ProgressBar"
            app:layout_constraintTop_toBottomOf="@id/progress1"
            app:layout_constraintEnd_toStartOf="@id/barrier" />

    <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

    <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Longer Text"
            app:layout_constraintTop_toBottomOf="@id/text1"
            app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
当文本到达进度条时,它将导致文本换行到下一行。如果不希望文本换行,可以添加省略号或将
TextView
的最大行数限制为1行


或者,您可以将左侧
文本视图的
宽度设置为
0
,这样它会占用进度条左侧的所有可用空间。

使用
开始
方向创建一个
屏障
,并引用右侧
文本视图
的所有ID。将每个进度条的
结束
约束到
屏障
屏障
将与最长的
文本视图
的开头对齐

如何实现这一点的示例XML:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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">

    <androidx.constraintlayout.widget.Barrier
            android:id="@+id/barrier"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            app:barrierDirection="start"
            app:constraint_referenced_ids="text1,text2"/>

    <TextView
            android:id="@+id/progress1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ProgressBar"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toStartOf="@id/barrier" />

    <TextView
            android:id="@+id/progress2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="ProgressBar"
            app:layout_constraintTop_toBottomOf="@id/progress1"
            app:layout_constraintEnd_toStartOf="@id/barrier" />

    <TextView
            android:id="@+id/text1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Text"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintEnd_toEndOf="parent" />

    <TextView
            android:id="@+id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Longer Text"
            app:layout_constraintTop_toBottomOf="@id/text1"
            app:layout_constraintEnd_toEndOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
当文本到达进度条时,它将导致文本换行到下一行。如果不希望文本换行,可以添加省略号或将
TextView
的最大行数限制为1行


或者,您可以将左侧
TextView的
宽度设置为
0
,这样它会占用进度条左侧的所有可用空间。

是的,您可以通过使用约束布局或RelativeLayout来实现这一点。在Relativelayout中,将文本与allignparenEnd对齐,并将进度条与startof对齐text@Raza:但在这种情况下,每个进度条将与其右侧的文本对齐,而我希望进度条彼此从上到下对齐,并与较大的文本对齐。请使用要显示的列表项。或者这是包含这些项目的静态视图。?@Raza:static Views您可以通过使用约束布局或RelativeLayout来实现这一点。在Relativelayout中,将文本与allignparenEnd对齐,并将进度条与startof对齐text@Raza:但在这种情况下,每个进度条将与其右侧的文本对齐,而我希望进度条彼此从上到下对齐,并与较大的文本对齐。请使用要显示的列表项。或者这是包含这些项目的静态视图。?@Raza:static Views这似乎很有效,但我现在遇到的问题是,如果左侧的
Foo
文本太长,它会与进度条重叠。我想我需要某种方法来阻止textview重叠如果文本太长,它确实会被包装,但是在预览中,包装文本的顶部位于父级
ConstraintLayout
上方,看起来被切断了。您是否设置了
top
约束?我已将顶部和底部设置为与右侧进度条的顶部和底部对齐,使其居中这似乎是一种工作,但我现在遇到的问题是如果左侧的
Foo
文本过长,则会与进度条重叠。我想我需要某种方法来阻止textview重叠如果文本太长,它确实会被包装,但是在预览中,包装文本的顶部位于父级
ConstraintLayout
上方,看起来好像被切断了。是否设置了
top
约束?我已将顶部和底部设置为与右侧进度条的顶部和底部对齐,使其居中