Android : List view - auto modify height

on Saturday, August 16, 2014


I'm learning Android and now I have this tutorial: http://www.informit.com/articles/article.aspx?p=1928230


I modify (I want scroll all page) this and i have:



<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ScrollView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >

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


<ListView
android:id="@+id/petList"
android:layout_width="wrap_content"
android:layout_height="700dp" //here!!!!
android:divider="#000"
/>

<Button
android:id="@+id/ButtonAddNews"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add new Pet" >
</Button>
</LinearLayout>

</ScrollView>


Single item:



<LinearLayout
android:id="@+id/relative"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="5dp"
orientation="horizontal">
<TextView
android:id="@+id/TextView01"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textColor="#f00"
android:layout_alignParentLeft="true"
android:text="two" ></TextView>
<TextView
android:id="@+id/TextView02"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textColor="#f00"
android:text="three"
android:layout_alignParentRight="true"></TextView>
</LinearLayout>


This working ok, but i must modify android:layout_height.


For example if i have 3 item in list then 700dp it is too more. If I use fill_parent, match_parent or wrap_content then this show me only one item (I can scroll it).


What I have to type in the layout_height to automatically expanding, with the number of items?


0 comments:

Post a Comment