2013-10-24 27 views
1

我需要按鈕出現在列表視圖下方。任何幫助將不勝感激。我已經嘗試了不同的方式來讓這個特定的佈局在Android上正確顯示,但到目前爲止我還沒有弄清楚這一點。我希望能夠在應用程序中間顯示一個列表視圖,並在列表視圖下有按鈕。問題是我有其他的東西需要顯示在列表視圖頂部的屏幕上,如標籤和旋鈕。列表視圖中的所有項目都將同時具有圖像和圖像右側的一些文本。我想實現的圖像是這樣的形象...android應用程序中的listview下的按鈕

android layout image

這裏是我到目前爲止的代碼...

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:maxLines="100" 
    android:orientation="vertical" 
    android:scrollbars="vertical" > 

    <Button 
     android:id="@+id/readWebpage" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:onClick="onClick" 
     android:text="Load Webpage" > 
    </Button> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:maxLines="100" 
     android:gravity="center" 
     android:layout_centerHorizontal="true" 
     android:layout_centerInParent="true" 
     android:orientation="horizontal"> 

     <Spinner 
      android:id="@+id/genre" 
      android:entries="@array/genre_list" 
      android:layout_weight="0.40" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="1dp" /> 

     <Spinner 
      android:id="@+id/sort" 
      android:entries="@array/sort_list" 
      android:layout_weight="0.40" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="1dp" /> 

     <Spinner 
      android:id="@+id/page" 
      android:entries="@array/page_list" 
      android:layout_weight="0.20" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="1dp" /> 

    </LinearLayout> 

    <LinearLayout 
      android:orientation="vertical" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

     <ListView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:id="@+id/listView" /> 

     <Button 
      android:id="@+id/previousPage" 
      android:layout_weight="0.50" 
      android:layout_width="0dp" 
      android:layout_height="40dp" 
      android:onClick="onClick" 
      android:layout_alignParentBottom="true" 
      android:text="Previous Page" > 
     </Button> 

     <Button 
      android:id="@+id/nextPage" 
      android:layout_weight="0.50" 
      android:layout_width="0dp" 
      android:layout_height="40dp" 
      android:onClick="onClick" 
      android:layout_alignParentBottom="true" 
      android:text="Next Page" > 
     </Button> 

    </LinearLayout> 

</LinearLayout> 

回答

0

使用RelativeLayout控制的ListView位置。

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 
    <Button 
     android:id="@+id/readWebpage" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:onClick="onClick" 
     android:text="Load Webpage" > 
    </Button> 
    <LinearLayout 
     android:id="@+id/spinner" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/readWebpage" 
     android:layout_marginTop="1dp" 
     android:orientation="horizontal" > 
     <Spinner 
      android:id="@+id/genre" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.40" 
      android:entries="@array/genre_list" /> 
     <Spinner 
      android:id="@+id/sort" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.40" 
      android:entries="@array/sort_list" /> 
     <Spinner 
      android:id="@+id/page" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.20" 
      android:entries="@array/page_list" /> 
    </LinearLayout> 
    <ListView 
     android:id="@+id/listView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/button" 
     android:layout_below="@+id/spinner" /> 
    <LinearLayout 
     android:id="@+id/button" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:orientation="horizontal" > 
     <Button 
      android:id="@+id/previousPage" 
      android:layout_width="0dp" 
      android:layout_height="40dp" 
      android:layout_weight="0.50" 
      android:onClick="onClick" 
      android:text="Previous Page" > 
     </Button> 
     <Button 
      android:id="@+id/nextPage" 
      android:layout_width="0dp" 
      android:layout_height="40dp" 
      android:layout_weight="0.50" 
      android:onClick="onClick" 
      android:text="Next Page" > 
     </Button> 
    </LinearLayout> 
</RelativeLayout> 
+0

這幫助我看到如何正確設置我的代碼。謝謝! – hopefulcd

0

設置按鈕的layout_weight爲0,然後列表視圖的layout_weight設置爲1。layout_weight是使用分配額外的空間,所以按鍵將保持其40dip高度和列表視圖將擴大到取up剩餘空間

0

使用下面的代碼;

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:maxLines="100" 
    android:orientation="vertical" 
    android:scrollbars="vertical" > 

    <Button 
     android:id="@+id/readWebpage" 
     android:layout_width="match_parent" 
     android:layout_height="40dp" 
     android:onClick="onClick" 
     android:text="Load Webpage" > 
    </Button> 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_centerInParent="true" 
     android:gravity="center" 
     android:maxLines="100" 
     android:orientation="horizontal" > 

     <Spinner 
      android:id="@+id/genre" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="1dp" 
      android:layout_weight="0.40" 
      android:entries="@array/genre_list" /> 

     <Spinner 
      android:id="@+id/sort" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="1dp" 
      android:layout_weight="0.40" 
      android:entries="@array/sort_list" /> 

     <Spinner 
      android:id="@+id/page" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_centerHorizontal="true" 
      android:layout_marginTop="1dp" 
      android:layout_weight="0.20" 
      android:entries="@array/page_list" /> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical" > 

     <ListView 
      android:id="@+id/listView" 
      android:layout_weight="3" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

     <LinearLayout 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="horizontal" 
      android:layout_weight="1" > 

      <Button 
       android:id="@+id/previousPage" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_weight="1" 
       android:onClick="onClick" 
       android:text="Previous Page" > 
      </Button> 

      <Button 
       android:id="@+id/nextPage" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_weight="1" 
       android:onClick="onClick" 
       android:text="Next Page" > 
      </Button> 
     </LinearLayout> 
    </LinearLayout> 

</LinearLayout> 
相關問題