Я пытаюсь использовать GridView, чтобы показать 4 части контента. В приведенном ниже коде это содержимое является только ImageView, но позже будет добавлен текстовый файл. Я создал 2x2 GridView, и я ожидал, что пространство экрана будет разделено поровну на все 4 ячейки сетки, но этого не происходит. Если установлено значение fill_parent
, ячейка принимает весь экран (например, изображение ниже), если установлено значение wrap_content
, ячейки заполняются рядом с одним из углов. Как я могу получить ячейку для равномерного распределения только с файлом макета XML?GridView равное распределение пространства
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:rowCount="2"
android:orientation="horizontal"
android:columnCount="2">
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_rowSpan="1"
android:layout_columnSpan="1"
android:layout_column="0"
android:layout_row="0">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/placeholder" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_columnSpan="1"
android:layout_rowSpan="1"
android:layout_column="1"
android:layout_row="0">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView"
android:src="@drawable/placeholder" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_rowSpan="1"
android:layout_columnSpan="1"
android:layout_column="1"
android:layout_row="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView3"
android:src="@drawable/placeholder" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_rowSpan="1"
android:layout_columnSpan="1"
android:layout_column="0"
android:layout_row="1">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:src="@drawable/placeholder" />
</LinearLayout>
</GridLayout>
</LinearLayout>
Любая причина, по которой вы не просто используете 'LinearLayout' с весами? – tachyonflux
Если у меня тоже, то я это сделаю, но я считаю, что это решение совсем не изящно, он чувствует себя так же, как грубый, заставляющий вас выйти из проблемы. – AmiguelS