Reputation: 105
I try to place a ListView
under a WebView
, to do this I use the folloing xml code:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/bg"
android:orientation="vertical"
android:scrollbars="vertical" >
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:textColor="#FFDEC2" />
<ListView
android:id="@+id/comments"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
</ListView>
</LinearLayout>
</ScrollView>
The code displays the content of the WebView
and ListView
correctly, but the ListView
just has the high of about 1.5 times the ListView
Item, so not the entire List is displayed but just the first Items.
I tried several combinations of android:layout_height="fill_parent"
and android:layout_height="wrap_content"
in the LinearLayout
, WebView
, ListView
and the surrounding ScrollView
, none of them worked.
Upvotes: 1
Views: 1743
Reputation: 26557
You should use layout weights. It's a way to use percentages to define your layout.
In the following example, the ListView uses 60% of the space, and the WebView 40% :
<LinearLayout
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:weightSum="1.0" >
<WebView
android:id="@+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:cacheColorHint="#00000000"
android:textColor="#FFDEC2"
android:layout_weight=".40" />
<ListView
android:id="@+id/comments"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".60" >
</ListView>
</LinearLayout>
Just change these percentages to whatever you want.
Upvotes: 3