2010-11-25 61 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