我需要为左侧的行创建一个带有标签的方格。网格应使用设备上可用的整个空间,同时保持宽度=高度。由于此网格有多行和多列自动调整,我认为使用自定义ConstraintLayout
符合该要求。
在下面的代码中,用于"肖像"布局,如果我将SCFrame视图的layout_width设置为
match_parent
:网格的大小符合预期,但未应用gravity
和textView10
字段的textView11
wrap_content
:网格折叠为0dpx0dp 0dp
:与wrap_content
相同,我认为这与ConstraintLayout
的文档不符合"使用0dp,相当于{ {1}}" MATCH_CONSTRAINT
:SCFrame网格是正方形,宽度= xxxdp,高度= xxxdp,xxxdp
和gravity
字段的textView10
已正确应用我应该在下面的代码中更改以获得正方形的网格并使用整个屏幕宽度(无论使用的设备是什么,并为标签列留出空间),并使用正确的textView11
标签?
gravity
这是自定义ConstraintLayout的代码:
<?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:id="@+id/scMainFrame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/actionBarSize"
app:layout_constraintHorizontal_chainStyle="spread_inside"
app:layout_constraintVertical_chainStyle="spread_inside"
app:layout_optimizationLevel="chains"
tools:context=".MainActivity"
tools:layout_behavior="@string/appbar_scrolling_view_behavior">
<TextView
android:id="@+id/textView10"
android:layout_width="14dp"
android:layout_height="0dp"
android:gravity="center_vertical"
android:text="A"
android:background="#FF0000"
app:layout_constraintTop_toTopOf="@+id/SCFrame"
app:layout_constraintRight_toLeftOf="@+id/SCFrame"
app:layout_constraintBottom_toTopOf="@+id/textView11" />
<TextView
android:id="@+id/textView11"
android:layout_width="14dp"
android:layout_height="0dp"
android:gravity="center_vertical"
android:text="B"
android:background="#FF0000"
app:layout_constraintTop_toBottomOf="@+id/textView10"
app:layout_constraintRight_toLeftOf="@+id/SCFrame"
app:layout_constraintBottom_toBottomOf="@+id/SCFrame" />
<be.ema.sclibrary.SCConstraintLayout
android:id="@+id/SCFrame"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:layout_marginLeft="14dp"
android:background="#0000FF"
app:layout_constraintLeft_toRightOf="@+id/textView10"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<TextView
android:id="@+id/A1"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="this is A1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toLeftOf="@+id/A2"
app:layout_constraintBottom_toTopOf="@+id/B1" />
<TextView
android:id="@+id/A2"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="this is A2"
app:layout_constraintLeft_toRightOf="@+id/A1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/B2" />
<TextView
android:id="@+id/B1"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="this is B1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/A1"
app:layout_constraintRight_toLeftOf="@+id/B2"
app:layout_constraintBottom_toBottomOf="parent" />
<TextView
android:id="@+id/B2"
android:layout_width="0dp"
android:layout_height="0dp"
android:text="this is B2"
app:layout_constraintLeft_toRightOf="@+id/B1"
app:layout_constraintTop_toBottomOf="@+id/A1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</be.ema.sclibrary.SCConstraintLayout>
</android.support.constraint.ConstraintLayout>