Questions tagged «constraint-layout-chains»


7
约束布局垂直对齐中心
如何在约束布局中垂直对齐和居中对象?可以垂直或水平对齐,但是除了约束两条网格线之间的视图外,我还没有找到一种同时居中的方法。 垂直对齐中心: 居中似乎是约束布局的一个巨大问题,它迫使我回到“ centerInParent”,“ centerVertical”和“ centerHorizo​​ntal”的相对布局。 我想使用约束布局创建以红色框出的布局: 不幸的是,我发现不使用两条网格线的唯一方法是使用嵌套的Relative和LinearLayouts(应该使用约束布局来解决这种确切的情况!)。 使用相对和线性布局的布局: <RelativeLayout android:layout_width="0dp" android:layout_height="wrap_content" android:layout_marginTop="12dp" app:layout_constraintTop_toBottomOf="@id/user_points" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent"> <LinearLayout android:id="@+id/stat_1_layout" android:layout_width="60dp" android:layout_height="wrap_content" android:layout_marginLeft="12dp" android:layout_marginRight="12dp" android:layout_centerVertical="true" android:layout_toLeftOf="@+id/divider_1" android:orientation="vertical"> <TextView android:id="@+id/stat_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:gravity="center_horizontal" android:text="10" android:textSize="16dp" android:textColor="@color/textSecondaryDark" android:maxLines="1"/> <TextView android:id="@+id/stat_detail_1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_horizontal" android:gravity="center" android:text="Streak" android:textSize="8sp" android:textColor="@color/textSecondary" android:maxLines="1"/> </LinearLayout> <View android:id="@+id/divider_1" android:layout_width="1dp" android:layout_height="38dp" …
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.