1

I have tried all kinds of help from other posts (setting widths to 0dp etc.) but nothing seems to work.

I have 2 layouts and the first one still seems to dominate. If I put background colors on the textviews, they are behaving themselves and end correctly. However put a background on the linear layout and it is almost 3/4 of the screen!?

<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:id="@+id/rowkRow"
    android:background="@color/RowBkgColor" android:gravity="center_vertical"
    android:minHeight="60dp">
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:id="@+id/rowleftImage"
        android:padding="3dip" android:gravity="left" android:layout_weight="0" />

    <LinearLayout android:orientation="vertical"
        android:layout_weight="0" android:layout_width="wrap_content"
        android:layout_height="wrap_content">
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/rowtext1"
            android:padding="3dip" android:gravity="left" android:typeface="sans"
            android:textStyle="bold" android:text="First Text" android:textSize="40dp"
            android:textColor="#FF333344" android:visibility="visible" 
             />
        <TextView android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:id="@+id/rowtext3"
            android:padding="3dip" android:gravity="center" android:typeface="sans"
            android:textStyle="bold" android:text="First Text" android:textSize="10dp"
            android:textColor="#FF333344" android:visibility="visible"
            android:background="#606060"
             />
    </LinearLayout>

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

        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/rowtext4"
            android:padding="3dip" android:gravity="right" android:text="Fourth Text"
            android:textSize="10dp" android:textStyle="bold" android:textColor="@color/RowTextColor"
            android:visibility="visible" />
        <TextView android:layout_width="fill_parent"
            android:layout_height="wrap_content" android:id="@+id/rowtext2"
            android:padding="3dip" android:gravity="left" android:text="Second Text"
            android:textSize="17dp" android:textStyle="bold" android:textColor="@color/RowTextColor"
            />
    </LinearLayout>

    <ImageView android:id="@+id/rowrightImage"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:padding="3dip" android:layout_weight="0" android:gravity="right" />
</TableRow>
double-beep
  • 5,031
  • 17
  • 33
  • 41
Dan Harvey
  • 798
  • 1
  • 10
  • 23
  • Your LinearLayouts have `android:layout_width="wrap_content"` attributes, so I suppose they just behave as you asked them, but the content to wrap is not filling the screen, but only about 3/4. Try to use "fill_parent" instead. – Adinia Aug 18 '11 at 07:53

1 Answers1

8

Do the following things. U can solve your problem.

  • set the android:layout_width of the children to "0dp"
  • set the android:weightSum of the parent
  • set the android:layout_weight of each child proportionally (e.g. weightSum = "5", three children: layout_weight="1", layout_weight="3", layout_weight="1")
Hussain
  • 5,552
  • 4
  • 40
  • 50
  • Thanks for the comment about weightSum, really helped me out! – icecreamman Sep 09 '11 at 20:11
  • 3
    @Hussain You should give credit to the user I think you copy past from witch I think is (Anke) http://stackoverflow.com/questions/2698817/linear-layout-and-weight-in-android – BrainCrash Oct 25 '11 at 13:26