2013-07-22 33 views
0

我想用下面的三個按鈕實現一個listView。我的xml由下面的代碼給出,但問題是按鈕的位置。在我第一次只使用線性的時候,但是在一段時間內,按鈕的動作是反轉的。所以,我應該用相對佈局如何使用按鈕生成ListView?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:padding="3dp" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" 
     android:padding="3dp" > 

     <ListView 
      android:id="@+id/list" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_marginTop="5dp" 
      android:layout_weight="1" /> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_alignParentBottom="true" 
      android:layout_below="@+id/listView" 
      android:layout_margin="0dp" 
      android:orientation="horizontal" 
      android:padding="0dp" > 

      <Button 
       android:id="@+id/retour" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="0dp" 
       android:layout_weight="1" 
       android:padding="0dp" 
       android:text="@string/cancel" /> 

      <Button 
       android:id="@+id/Actualise" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="0dp" 
       android:layout_weight="1" 
       android:gravity="center|center_vertical" 
       android:padding="0dp" 
       android:text="Actualiser la liste" /> 

      <Button 
       android:id="@+id/testbutton" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_margin="0dp" 
       android:layout_weight="1" 
       android:padding="0dp" 
       android:text="@string/selection" /> 
     </RelativeLayout> 
    </RelativeLayout> 

</LinearLayout> 
+0

你的列表視圖下面的相對佈局應該只是一個線性佈局 – njzk2

+0

我試過這個,我將按鈕的列表視圖 – user2591941

回答

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:orientation="vertical" > 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="match_parent" 
     android:layout_height="379dp" > 
    </ListView> 

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

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight=".33" 
      android:layout_gravity="center" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight=".33" 
      android:layout_gravity="center" 
      android:text="Button" /> 

     <Button 
      android:id="@+id/button3" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight=".33" 
      android:layout_gravity="center" 
      android:text="Button" /> 

    </LinearLayout> 

</LinearLayout> 
0

試試這個代碼,它工作正常顯示列表視圖qith下面列表視圖

<?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" > 

<ListView 
    android:id="@+id/listView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_above="@+id/linearLayout1" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" > 
</ListView> 

<LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentRight="true" 
    android:id="@+id/linearLayout1" 
    android:weightSum="3" 
    > 

    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Button" /> 
</LinearLayout> 

三粒扣