2010-11-25 88 views
0

我在我的android應用程序中有一個LinearLayout。Android GridView隱藏我的按鈕

只有兩個按鈕效果不錯 - 但是當我添加了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" /> 

回答

0

我解決了這個 - 這是因爲根級別的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"/> 

+0

的引用文字保持隱藏XML文檔的部分。上面的Xml具有一個根層次的LinearLayout,其方向設置爲'vertical'。 – KennetRunner 2010-11-29 21:20:23