【发布时间】:2018-12-30 00:32:57
【问题描述】:
我制作了一个 gridLayout,列数和行数分别设置为 3。当我复制并粘贴 X 的代码(我将制作井字游戏)时,它会溢出并且不会更改行,而在模拟器中它会显示在下一行。
我应该怎么做才能让它显示在设计页面中?
XML 代码是:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.v7.widget.GridLayout
android:id="@+id/gridLayout"
android:layout_width="368dp"
android:layout_height="368dp"
android:layout_margin="8dp"
android:background="@drawable/board"
app:columnCount=" 3"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:rowCount=" 3">
<ImageView
android:id="@+id/imageView1"
android:layout_width="100dp"
android:layout_height=" 100dp"
android:layout_margin=" 8dp"
app:srcCompat="@drawable/x" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="100dp"
android:layout_height=" 100dp"
android:layout_margin=" 8dp"
app:srcCompat="@drawable/x" />
<ImageView
android:id="@+id/imageView3"
android:layout_width="100dp"
android:layout_height=" 100dp"
android:layout_margin=" 8dp"
app:srcCompat="@drawable/x" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="100dp"
android:layout_height=" 100dp"
android:layout_margin=" 8dp"
app:srcCompat="@drawable/x" />
</android.support.v7.widget.GridLayout>
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
将行数设为 1 并将
LinearLayout放入GridLayout使用weight_sum' inLinearLayout` 并将ImageView放入LinearLayout
标签: java android layout grid-layout