Android Listview

Asked

Viewed 218 times

2

How can I get a Listview to assemble the items as follows:

When you have only one item it occupies the entire screen, if you have two divide 50% of the screen size between the items and so on...

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
   xmlns:tools="http://schemas.android.com/tools"
   android:id="@+id/RelativeLayout1"  
   android:layout_width="match_parent"  
   android:layout_height="match_parent"  
   android:orientation="vertical"
   tools:context=".ListViewActivity" >  

<ListView
    android:id="@+id/listaromaneiosview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@color/Black"
    android:dividerHeight="5dp"
    tools:listitem="@layout/cre_004_listaromaneios_adpter" >

</ListView>

<TextView 
    android:id="@+id/textoListView"
    android:text=""
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:layout_weight="3"
    android:textSize="@dimen/titulo"/>

<ImageButton
    android:id="@+id/selecionaRomaneio"
    android:layout_width="30dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"
    android:layout_weight="1"
    android:background="@color/White"
    android:contentDescription="@string/app_name"
    android:maxWidth="100dp"
    android:onClick="actionListner"
    android:src="@android:drawable/ic_menu_delete" />

  • Try to place their height as fill_parent.

  • I tried it didn’t work out, he wasn’t on the full screen..

  • Which layout are you using?

  • Relativelayout and Linearlayout for the list item

  • Listview needs to stay as fill_parent and the parent element of the Adapter that Textview and Imagebutton need to be as fill_parent as well. Try it this way I believe it should work!

  • I think this behavior is not possible, maybe you will have to do "in hand" using a LinearLayout and using the weight and weightSum of children.

Show 1 more comment

1 answer

2


ListView, from the point of view of children, has infinite height, does not make sense a match_parent. What you need is a LinearLayout (don’t forget the orientation="vertical") and adds the children with layout_height="0dp" and layout_weight="1" (value does not matter, as long as it is the same for all items). For performance reasons, put also the weightSum in the LinearLayout as the sum of the weights (Weight) of the children. It is possible to do this at runtime also with setWeightSum().

  • thank you I’ll test !!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.