Reputation: 2311
I want to set UI based on android:layout_weight
.I have following code structure
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="25"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="25"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
</LinearLayout>
<ListView
android:id="@+id/relatedContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:layout_weight="50"
here=""
problem=""
android:cacheColorHint="@android:color/transparent"
android:divider="@drawable/divider"
android:listSelector="@drawable/listview_selector_color" >
</ListView>
Everything work properly but when we set ListView id then it streatch all layout.So please can anyone help me out about this.Thanks
Upvotes: 1
Views: 7511
Reputation: 408
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="25"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="25"
android:orientation="horizontal" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button1" />
</LinearLayout>
<ListView
android:id="@+id/relatedContent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_marginBottom="60dp"
android:layout_weight="50"
android:cacheColorHint="@android:color/transparent" >
</ListView>
Upvotes: 0
Reputation: 5803
Put your list view
inside a linear layout
and give layout_weight="50"
to the linear layout
.Then make the listview
width and height to fill parent
.
Also give linear_layout layout height="0dp"
Upvotes: 0
Reputation: 68187
You need to alter your xml as below:
//alter both LinearLayout as
android:layout_weight="25"
android:layout_height="0dp"
//alter ListView as
android:layout_weight="50"
android:layout_height="0dp"
android:isScrollContainer="false"
Upvotes: 1