1

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

QED
  • 9,803
  • 7
  • 50
  • 87
Dilip
  • 2,271
  • 5
  • 32
  • 52
  • 1
    if you're setting listview's android:layout_weight="50" then you should set its height to "0px" so it'll set it %50 of parent view. – yahya Oct 15 '12 at 10:22

3 Answers3

1

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"
waqaslam
  • 67,549
  • 16
  • 165
  • 178
0

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"

Renjith
  • 5,783
  • 9
  • 31
  • 42
0

<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>

QED
  • 9,803
  • 7
  • 50
  • 87
Hitesh Jain
  • 408
  • 2
  • 5