Android 将最大视图的左侧与约束布局对齐
嗨,我想做一个时间表视图。 如果用户as设置为24小时显示或不显示,则开放时间的格式会更改。有一天商店就要关门了。关闭的字符串是动态的,它可以每天发生,它来自VM.days.getX.time 现在我得到的是: 我想把这个小时的左边对齐 这是我的生日礼物Android 将最大视图的左侧与约束布局对齐,android,android-layout,android-constraintlayout,Android,Android Layout,Android Constraintlayout,嗨,我想做一个时间表视图。 如果用户as设置为24小时显示或不显示,则开放时间的格式会更改。有一天商店就要关门了。关闭的字符串是动态的,它可以每天发生,它来自VM.days.getX.time 现在我得到的是: 我想把这个小时的左边对齐 这是我的生日礼物 <android.support.constraint.ConstraintLayout android:layout_width="match_parent" android:layout_height="wrap_c
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/base_space">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/small_space"
android:text="@{VM.title}"
android:textStyle="bold"
tools:text="Heures de la semaine" />
<android.support.constraint.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="start"
app:constraint_referenced_ids="first_time,second_time,third_time,fourth_time,fifth_time,sixth_time" />
<TextView
android:id="@+id/first_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(0).day}"
android:textColor="@{VM.days.get(0).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(0).isBold}"
app:layout_constraintTop_toBottomOf="@id/title"
tools:text="Sunday" />
<TextView
android:id="@+id/first_time"
app:layout_constraintLeft_toLeftOf="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(0).time}"
android:textColor="@{VM.days.get(0).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(0).isBold}"
app:layout_constraintBottom_toBottomOf="@+id/first_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/barrier"
app:layout_constraintTop_toTopOf="@+id/first_day"
tools:text="8:30 AM - 9:00 PM" />
<TextView
android:id="@+id/second_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(1).day}"
android:textColor="@{VM.days.get(1).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(1).isBold}"
app:layout_constraintTop_toBottomOf="@id/first_day"
tools:text="Monday" />
<TextView
android:id="@+id/second_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(1).time}"
android:textColor="@{VM.days.get(1).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(1).isBold}"
app:layout_constraintBottom_toBottomOf="@+id/second_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintLeft_toLeftOf="@+id/barrier"
app:layout_constraintStart_toStartOf="@+id/barrier"
app:layout_constraintTop_toTopOf="@+id/second_day"
tools:text="Closed" />
<TextView
android:id="@+id/third_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(2).day}"
android:textColor="@{VM.days.get(2).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(2).isBold}"
app:layout_constraintTop_toBottomOf="@id/second_day"
tools:text="Tuesday" />
<TextView
android:id="@+id/third_time"
app:layout_constraintLeft_toLeftOf="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(2).time}"
android:textColor="@{VM.days.get(2).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(2).isBold}"
app:layout_constraintBottom_toBottomOf="@+id/third_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/barrier"
app:layout_constraintTop_toTopOf="@+id/third_day"
tools:text="8:00 - 21:00" />
<TextView
android:id="@+id/fourth_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(3).day}"
android:textColor="@{VM.days.get(3).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(3).isBold}"
app:layout_constraintTop_toBottomOf="@id/third_day"
tools:text="Wednesday" />
<TextView
android:id="@+id/fourth_time"
app:layout_constraintLeft_toLeftOf="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(3).time}"
android:textColor="@{VM.days.get(3).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(3).isBold}"
app:layout_constraintBottom_toBottomOf="@+id/fourth_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/barrier"
app:layout_constraintTop_toTopOf="@+id/fourth_day"
tools:text="8:00 - 21:00" />
<TextView
android:id="@+id/fifth_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(4).day}"
android:textColor="@{VM.days.get(4).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(4).isBold}"
app:layout_constraintTop_toBottomOf="@id/fourth_day"
tools:text="Thursday" />
<TextView
android:id="@+id/fifth_time"
app:layout_constraintLeft_toLeftOf="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(4).time}"
android:textColor="@{VM.days.get(4).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(4).isBold}"
app:layout_constraintBottom_toBottomOf="@+id/fifth_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/barrier"
app:layout_constraintTop_toTopOf="@+id/fifth_day"
tools:text="8:00 - 21:00" />
<TextView
android:id="@+id/sixth_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(5).day}"
android:textColor="@{VM.days.get(5).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(5).isBold}"
app:layout_constraintTop_toBottomOf="@id/fifth_day"
tools:text="Friday" />
<TextView
android:id="@+id/sixth_time"
app:layout_constraintLeft_toLeftOf="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(5).time}"
android:textColor="@{VM.days.get(5).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(5).isBold}"
app:layout_constraintBottom_toBottomOf="@+id/sixth_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/barrier"
app:layout_constraintTop_toTopOf="@+id/sixth_day"
tools:text="8:00 - 21:00" />
<TextView
android:id="@+id/seventh_day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(6).day}"
android:textColor="@{VM.days.get(6).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(6).isBold}"
app:layout_constraintTop_toBottomOf="@id/sixth_day"
tools:text="Saturday" />
<TextView
android:id="@+id/seventh_time"
app:layout_constraintLeft_toLeftOf="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(6).time}"
android:textColor="@{VM.days.get(6).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(6).isBold}"
app:layout_constraintBottom_toBottomOf="@+id/seventh_day"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/barrier"
app:layout_constraintTop_toTopOf="@+id/seventh_day"
tools:text="8:00 - 21:00" />
</android.support.constraint.ConstraintLayout>
我尝试将所有的timeUI宽度设置为0dp,从barrier开始,设置为parent。但是,如果所有的timeUI都有这些约束,那么它们都会消除这些约束,有很多解决方案: 1-使用具有两个垂直线性布局位置起点和终点的框架布局 2-如果您坚持使用约束布局,您可以尝试为右侧的文本视图指定宽度
3-我真的不确定会发生什么,但您可以尝试使闭合的一个宽度匹配父项,而不是包裹内容有许多解决方案: 1-使用具有两个垂直线性布局位置起点和终点的框架布局 2-如果您坚持使用约束布局,您可以尝试为右侧的文本视图指定宽度
3-我真的不确定会发生什么,但您可以尝试使闭合的一个宽度与父级匹配,而不是将内容从闭合视图中删除右/端约束。这将使它左对齐:
<TextView
android:id="@+id/second_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(1).time}"
android:textColor="@{VM.days.get(1).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(1).isBold}"
app:layout_constraintBottom_toBottomOf="@id/second_day"
app:layout_constraintStart_toStartOf="@id/barrier"
app:layout_constraintTop_toTopOf="@id/second_day"
tools:text="Closed" />
另外,决定在左/右和开始/结束约束之间使用。两者兼备是多余的。此外,在引用视图时,不需要在其名称中包含+号。从关闭的视图中删除了右/端约束。这将使它左对齐:
<TextView
android:id="@+id/second_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@{VM.days.get(1).time}"
android:textColor="@{VM.days.get(1).highlight ? @color/red : @color/gray}"
app:isBold="@{VM.days.get(1).isBold}"
app:layout_constraintBottom_toBottomOf="@id/second_day"
app:layout_constraintStart_toStartOf="@id/barrier"
app:layout_constraintTop_toTopOf="@id/second_day"
tools:text="Closed" />
另外,决定在左/右和开始/结束约束之间使用。两者兼备是多余的。此外,在引用视图时,不需要在其名称中包含+符号。您也可以使用
使用屏障时,可以将“起点-屏障-终点”对齐,然后在屏障中放置要与屏障对齐的视图的所有ID,然后将屏障的方向设置为所有这些视图的起点:
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="end"
app:constraint_referenced_ids="textView1,textView2,..." />
你也可以用一个
使用屏障时,可以将“起点-屏障-终点”对齐,然后在屏障中放置要与屏障对齐的视图的所有ID,然后将屏障的方向设置为所有这些视图的起点:
<androidx.constraintlayout.widget.Barrier
android:id="@+id/barrier"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:barrierDirection="end"
app:constraint_referenced_ids="textView1,textView2,..." />
关闭的视图是动态的,它可能会更改它由VM.days.get1.timewould决定是否更容易将文本视图的文本更改为使用此颜色关闭?@JCDecary您可以根据文本视图的值以编程方式更改约束这里的许多线程提供了解决方案-例如。只要同时设置了开始和结束约束,您的文本将出现在中间。关闭视图是动态的,它可能会改变它的确定。V.May.GET1。更简单的是,仅仅改变文本视图的文本以与此颜色接近?@ JCDecary,可以根据TeXVIEW的值编程性地更改约束。-例如。只要你有开始和结束约束集,你的文本就会出现在中间。当你的解决方案,我做了一个线性布局,3视图包装/重量1 / WRAPI当你的解决方案,我做了一个线性布局,与3视图包装/重量1 /包裹。