Android GridView скрывает мои кнопки - PullRequest
0 голосов
/ 26 ноября 2010

У меня есть LinearLayout в моем приложении для Android.

Работал хорошо только с двумя кнопками - но когда я добавил GridView, теперь он скрывает две кнопки - независимо от того, поместил ли я их выше или ниже GridView

Может кто-нибудь помочь?

<?xml version="1.0" encoding="utf-8"?>

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/gridview"
android:layout_width="fill_parent" 
android:layout_height="wrap_content"
android:numColumns="4"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"/>

<Button android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_marginTop="5px"
android:layout_width="fill_parent"
android:text="@string/week" />
<Button android:layout_weight="1"
android:layout_marginTop="5px"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:text="@string/day" />

1 Ответ

0 голосов
/ 30 ноября 2010

Я решил это - это потому, что корневой уровень LinearLayout был установлен с горизонтальной ориентацией.

Я изменил это на «вертикальный», а затем обернул два элемента Button в их собственный LinearLayout с «горизонтальной» ориентацией - все работает так, как мне нужно сейчас.

Вот итоговый XML

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ffffff">

        <Button android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_marginTop="5px"
            android:layout_width="fill_parent"
            android:text="@string/week" />
        <Button android:layout_weight="1"
            android:layout_marginTop="5px"
            android:layout_height="wrap_content"
            android:layout_width="fill_parent"
            android:text="@string/day" />
</LinearLayout>

<GridView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/gridview"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:numColumns="4"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:stretchMode="columnWidth"
    android:gravity="center"/>

...