2013-07-22 4 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

Я пробовал это, у меня будет кнопка listview – 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

Попробуйте этот код он прекрасно работает, чтобы показать ListView qith три кнопки ниже 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" > 

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

Смежные вопросы