Проблемы с андроидом GridLayout

У меня есть два вопроса о моем GridLayout.

  1. Почему макет проходит мимо телефона, когда я сказал заполнить родительский, а родительский соответствует родительскому?
  2. Почему третий вид текста (тот, который говорит "Дата") становится заглушенным? Между тем, что говорит Резерв, и тем, что говорит дата, есть большое пространство.

Спасибо!

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/GridLayout1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:columnCount="2"
    android:rowCount="4"
    tools:context=".GridLayoutActivity" >

    <ImageView
        android:id="@+id/imgCabin1"
        android:layout_column="0"
        android:layout_row="0"
        android:layout_rowSpan="3"
        android:layout_height="248dp"
        android:scaleType="fitCenter"
        android:layout_width="200dp"
        android:src="@drawable/sky_beach" 
        android:background="#222222"/>

    <TextView
        android:id="@+id/txtCabint1Title"
        android:layout_width="fill_parent"
        android:layout_height="72sp"
        android:layout_column="1"
        android:layout_row="0"
        android:padding="10sp"
        android:text="Sky Beach"
        android:textSize="48sp" />

    <TextView
        android:id="@+id/txtCabinDesc"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_column="1"
        android:layout_gravity="left"
        android:layout_row="1"
        android:maxLines="5"
        android:padding="10sp"
        android:singleLine="false"
        android:text="Dog friendly vacation rental cabin on a scenic mountain river"
        android:textSize="24sp" />

    <TextView
        android:id="@+id/btnCabin1Reserve"
        android:layout_width="fill_parent"
        android:layout_height="60sp"
        android:background="#888888"
        android:gravity="left"
        android:layout_column="1"
        android:layout_row="2"
        android:text="Reserve"
        android:textSize="36sp" 
        android:padding="10sp"  />

    <TextView
        android:id="@+id/txtCabinDesc"
        android:layout_width="fill_parent"
        android:layout_height="60sp"
        android:layout_gravity="top"
        android:layout_column="1"
        android:layout_row="3"
        android:text="Date: "
        android:textSize="36sp" 
        android:padding="10sp"  />


</GridLayout>

1 ответ

Решение

Вместо того, чтобы использовать вид сетки, почему вы не используете относительный макет и устанавливаете свой макет относительно. Ваша вторая проблема заключается в том, что вы устанавливаете строку сетки один за другим, следовательно, после настройки просмотра изображений он устанавливает текстовое представление txtCabinDesc.. Попробуйте следующий код фрагмент, который я пробовал

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/GridLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:columnCount="2"
android:rowCount="4" >

<ImageView
    android:id="@+id/imgCabin1"
    android:layout_column="0"
    android:layout_row="0"
    android:layout_rowSpan="3"
    android:layout_height="248dp"
    android:scaleType="fitCenter"
    android:layout_width="200dp"
    android:src="@drawable/ic_launcher" 
    android:background="#222222"/>

<TextView
    android:id="@+id/txtCabint1Title"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/imgCabin1"
    android:layout_height="72sp"
    android:layout_column="1"
    android:layout_row="0"
    android:padding="10sp"
    android:text="Sky Beach"
    android:textSize="48sp" />

<TextView
    android:id="@+id/txtCabinDesc"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/imgCabin1"
    android:layout_below="@id/txtCabint1Title"
    android:layout_height="wrap_content"
    android:layout_column="1"
    android:layout_gravity="left"
    android:layout_row="1"
    android:maxLines="5"
    android:padding="10sp"
    android:singleLine="false"
    android:text="Dog friendly vacation rental cabin on a scenic mountain river"
    android:textSize="24sp" />

<TextView
    android:id="@+id/btnCabin1Reserve"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/imgCabin1"
    android:layout_below="@id/txtCabinDesc"
    android:layout_height="60sp"
    android:background="#888888"
    android:gravity="left"
    android:layout_column="1"
    android:layout_row="2"
    android:text="Reserve"
    android:textSize="36sp" 
    android:padding="10sp"  />

<TextView
    android:id="@+id/txtCabinDesc1"
    android:layout_width="match_parent"
    android:layout_toRightOf="@id/imgCabin1"
    android:layout_below="@id/btnCabin1Reserve"
    android:layout_height="60sp"
    android:layout_gravity="top"
    android:layout_column="1"
    android:layout_row="3"
    android:text="Date: "
    android:textSize="36sp" 
    android:padding="10sp"  />

Также измените свой идентификатор последнего textView, потому что он конфликтует с вашим идентификатором описания textView.

Другие вопросы по тегам