答案 0 :(得分:2)
将app:layout_constraintVertical_chainStyle="packed"
添加到第一个TextView中以更改链的样式。默认样式为spread
,它将在链接视图之间留一个空间以平均分布它们。 packed
样式会将它们打包在一起,默认偏差为0.5,这就是您想要的。
编辑更新的问题:
<?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">
<ImageView
android:id="@+id/vh_buisnesspost_buisness_preview"
android:layout_width="100dp"
android:layout_height="100dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_margin="16dp"
android:background="@drawable/background_circle_preview_border"/>
<TextView
android:id="@+id/vh_buisnesspost_buisness_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Buisness Name"
android:textStyle="bold"
android:textColor="@color/colorBlackFont"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintStart_toEndOf="@+id/vh_buisnesspost_buisness_preview"
app:layout_constraintTop_toTopOf="@+id/vh_buisnesspost_buisness_preview"
app:layout_constraintBottom_toTopOf="@+id/vh_buisnesspost_date_posted"
android:layout_marginStart="16dp"/>
<TextView
android:id="@+id/vh_buisnesspost_date_posted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text="2 mins ago"
app:layout_constraintStart_toEndOf="@+id/vh_buisnesspost_buisness_preview"
app:layout_constraintBottom_toBottomOf="@+id/vh_buisnesspost_buisness_preview"
app:layout_constraintTop_toBottomOf="@+id/vh_buisnesspost_buisness_name"
android:layout_marginStart="16dp"/>
<TextView
android:id="@+id/vh_buisnesspost_post_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="12sp"
android:text=" \u2022 Restaurant"
app:layout_constraintStart_toEndOf="@+id/vh_buisnesspost_date_posted"
app:layout_constraintBottom_toBottomOf="@+id/vh_buisnesspost_date_posted"
app:layout_constraintTop_toTopOf="@+id/vh_buisnesspost_date_posted"/>
</androidx.constraintlayout.widget.ConstraintLayout>
答案 1 :(得分:0)
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/vh_buisnesspost_buisness_preview"
app:layout_constraintStart_toEndOf="@+id/vh_buisnesspost_buisness_preview"
app:layout_constraintTop_toTopOf="@+id/vh_buisnesspost_buisness_preview">
<TextView
android:id="@+id/vh_buisnesspost_buisness_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="Buisness Name"
android:textColor="@color/colorAccent"
android:textStyle="bold"/>
<TextView
android:id="@+id/vh_buisnesspost_date_posted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:text="2 mins ago"
android:textSize="12sp"/>
</LinearLayout>
答案 2 :(得分:0)
尝试此示例,它不需要其他int[5]
I = 5
ViewGroup