2014-10-29 49 views
1

我的佈局設計有問題。當我嘗試在一個LinearLayout中添加一個GridView時,它使得這些控件不可見(在GridView下面)。GridView使相同佈局中的其他控件在RelativeLayout中不可見

我需要的設計是:

http://www.imagesup.net/pt-514145877008.png

我試圖與RelativeLayout的創建和使用一個GridView控件也。 下面是XML佈局文件:

purchase.xml

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:background="#FFFFFF"> 

    <LinearLayout 
     android:id="@+id/button_area" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="#FFFFFF" 
     android:orientation="vertical" 
     android:padding="10dp" > 


     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:text="One Year Subscription" 
      android:textColor="#000000" 
      android:textSize="18sp" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingBottom="10dp" 
      android:paddingTop="15dp" 
      android:text="Rs. 500" 
      android:textColor="#000000" 
      android:textSize="18sp" /> 

     <Button 
      android:id="@+id/button_continue" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_gravity="right" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="5dp" 
      android:background="#FF0000" 
      android:text="Buy" 
      android:textColor="#FFFFFF" > 

      <!-- continue button --> 
      <!-- select All check box --> 
     </Button> 
    </LinearLayout> 

     <View android:layout_width="match_parent" 
      android:layout_height="3dp" 
      android:layout_marginLeft="20dp" 
      android:layout_marginRight="20dp" 
      android:background="#CDCDCD"/> 

    <LinearLayout 
     android:id="@+id/monthly_subscription" 
     android:orientation="vertical" 
     android:layout_below="@+id/button_area" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:paddingBottom="10dp" 
      android:paddingTop="15dp" 
      android:text="monthly Subscription" 
      android:textColor="#000000" 
      android:textSize="18sp" />   
    <TextView 
     android:id="@+id/price_text" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_gravity="right" 
     android:layout_marginRight="5dp" 
     android:layout_weight="1" 
     android:gravity="right" 
     android:text="Rs 0" 
     android:textColor="#000000" 
     android:textSize="18sp" /> 

     <GridView 
     android:id="@+id/book_grid" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:numColumns="3" 
     android:padding="10dp" 
     tools:listitem="@layout/book_list_item" > 
    </GridView> 

    <Button 
      android:id="@+id/button_continue_bottom" 
      android:layout_width="match_parent" 
      android:layout_height="50dp" 
      android:layout_gravity="right" 
      android:layout_margin="10dp" 
      android:layout_marginBottom="5dp" 
      android:layout_marginTop="10dp" 
      android:background="#FF0000" 
      android:text="Buy" 
      android:textColor="#FFFFFF" > 
     </Button> 

    </LinearLayout> 


</RelativeLayout> 

在這裏,我得到了什麼,當我使用此代碼試過了,也包括結果,當我試圖通過GridView控件的可見性設置爲「水漲船高」

http://www.imagesup.net/pm-314145913100.png

什麼是錯我的設計?是什麼讓這些控件看不見?請幫助我將其設置爲我所需的佈局。

回答

0

你應該把你的底部按鈕放在線性佈局之外。試試這個代碼:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:background="#FFFFFF> 

<!-- Align to parent top--> 
<LinearLayout 
    android:id="@+id/button_area" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:background="#FFFFFF" 
    android:gravity="center" 
    android:orientation="vertical" 
    android:padding="10dp"> 


    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:text="One Year Subscription" 
     android:textColor="#000000" 
     android:textSize="18sp" /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:paddingBottom="10dp" 
     android:paddingTop="15dp" 
     android:text="Rs. 500" 
     android:textColor="#000000" 
     android:textSize="18sp" /> 

    <Button 
     android:id="@+id/button_continue" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_gravity="right" 
     android:layout_marginBottom="5dp" 
     android:layout_marginTop="5dp" 
     android:background="#FF0000" 
     android:text="Buy" 
     android:textColor="#FFFFFF"> 

     <!-- continue button --> 
     <!-- select All check box --> 
    </Button> 
</LinearLayout> 

<!-- layout below top linearlayout--> 
<View 
    android:id="@+id/line" 
    android:layout_width="match_parent" 
    android:layout_height="3dp" 
    android:layout_below="@+id/button_area" 
    android:layout_marginLeft="20dp" 
    android:layout_marginRight="20dp" 
    android:background="#CDCDCD" /> 

<!-- layout below line view but above bottom button--> 
<LinearLayout 
    android:id="@+id/monthly_subscription" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/button_continue_bottom" 
    android:layout_below="@+id/line" 
    android:orientation="vertical"> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:paddingBottom="10dp" 
     android:paddingTop="15dp" 
     android:text="monthly Subscription" 
     android:textColor="#000000" 
     android:textSize="18sp" /> 

    <TextView 
     android:id="@+id/price_text" 
     android:layout_width="wrap_content" 
     android:layout_height="0dp" 
     android:layout_gravity="right" 
     android:layout_marginRight="5dp" 
     android:layout_weight="1" 
     android:gravity="right" 
     android:text="Rs 0" 
     android:textColor="#000000" 
     android:textSize="18sp" /> 

    <GridView 
     android:id="@+id/book_grid" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:numColumns="3" 
     android:padding="10dp" 
     android:stretchMode="columnWidth" 
     tools:listitem="@layout/book_list_item"></GridView> 


</LinearLayout> 

<!-- layout outside of linear layout and align to parent bottom--> 
<Button 
    android:id="@+id/button_continue_bottom" 
    android:layout_width="match_parent" 
    android:layout_height="50dp" 
    android:layout_alignParentBottom="true" 
    android:layout_margin="10dp" 
    android:layout_marginBottom="5dp" 
    android:layout_marginTop="10dp" 
    android:background="#FF0000" 
    android:text="Buy" 
    android:textColor="#FFFFFF" /> 

</RelativeLayout> 
相關問題