Answer the question
In order to leave comments, you need to log in
Strange behavior of a ListView inside a LinearLayout?
Problem: If any item other than another ListView is below the original one, the top ListView shrinks it despite setting the Weight parameter.
the code
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
</ListView>
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="5"
android:scaleType="fitCenter"
android:src="@drawable/ic_launcher" />
</LinearLayout>
Answer the question
In order to leave comments, you need to log in
Set the ListView android:layout_height="0dp"
and it will have the expected option. In general, when using android:layout_weight
this control, it is desirable to set android:layout_height
(or respectively android:layout_width
) to 0dp. And the behavior will be more predictable, and it works faster. And the lower ImageView android:layout_weight
is probably not needed at all.
In general, it seems to me android:layout_height="wrap_content"
that ListView is a bad idea. Try making match_parent.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question