Android ListView

2

How can I have a ListView mount the items as follows:

When you have only one item it occupies the entire screen, if you have two, divide the screen size by 50% between 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" />

    
asked by anonymous 22.08.2014 / 15:03

1 answer

2

ListView , from the point of view of children, has infinite height, does not make sense match_parent . What you need is a LinearLayout (do not forget orientation="vertical" ) and add children with layout_height="0dp" and layout_weight="1" (the value does not matter as long as it is the same for all items). For performance reasons, also put weightSum into LinearLayout as the sum of the children's weight. You can do this at runtime also with setWeightSum() .

    
23.08.2014 / 04:28