2

This has puzzled me for two days now. I have a LinearLayout like the following:

        <LinearLayout
                android:background="@drawable/rounded_rect_wht_bg"
                android:layout_height="wrap_content"
                android:layout_width="fill_parent"
                android:orientation="horizontal"
                android:layout_margin="5dp"
                android:minHeight="30dp"
                android:padding="5dp"
                android:visibility="gone">
            <ImageView
                    android:id="@+id/timage"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="5dp"
                    android:layout_marginRight="10dp"
                    android:layout_marginLeft="10dp"
                    android:layout_marginBottom="5dp"
                    android:scaleType="fitXY"
                    />
            <TextView
                    android:id="@+id/tname"
                    android:layout_width="wrap_content"
                    android:layout_height="fill_parent"
                    android:layout_marginRight="5dp"
                    android:textColor="@android:color/black"
                    android:textSize="13sp"
                    android:textStyle="bold"/>
            <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical"
                    android:layout_marginLeft="5dp"
                    android:layout_marginRight="5dp"
                    android:src="@drawable/ticon" />
        </LinearLayout>

The last ImageView (ticon) doesn't showup. I only see timage and tname. But, if I switched it:

<LinearLayout>
        <ImageView android:src="@drawable/ticon" />
        <ImageView android:id="@+id/timage" />
        <TextView android:id="@+id/tname" />
</LinearLayout>

It's there. What is going on here?

3
  • Is that normal that your sample code shows an android:visibility="gone" on your layout ?
    – AsTeR
    Nov 23, 2011 at 22:48
  • Is the TextView width squeezing it out past the width of the screen? Also, I'm not sure if it's relevant, but I'm not sure the scaleType makes sense with the first ImageView if you're just don't wrap_content for its height & width anyway.
    – kabuko
    Nov 23, 2011 at 22:50
  • AsTeR: yes, it's normal. It's part of a larger layout where there's different components showing different things. Depending on what users are seeing, we show them up.
    – atedja
    Nov 23, 2011 at 22:51

2 Answers 2

2

The content of your TextView might be pushing out the ImageView. Try using layout_weight="1" to distribute all of the remaining space to the TextView.

0
0

Since you're defining the layout_height of your TextView as "fill_parent", it will take the remaining space. That's why it shows properly if it's declared last: the images use only the space they need (layout_height="wrap_content").

Depending on what you want to do, you can either try setting the layout_height of the TextView to "wrap_content" or, if you want the TextView to fill up the space between the images, I would suggest you to use RelativeLayout:

<RelativeLayout
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     ...>
     <ImageView
          android:id="@+id/timage"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          ...
          android:layout_alignParentTop="true" />
     <ImageView
          android:id="@+id/ticon"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          ...
          android:layout_alignParentBottom="true" />
     <TextView
          android:id="@+id/tname"
          android:layout_width="wrap_content"
          android:layout_height="fill_parent"
          ...
          android:layout_below="@+id/timage"
          android:layout_above="@+id/ticon" />
</RelativeLayout>
1
  • 1
    Yeah. I ended up using RelativeLayout. It still remains a mystery why the last ImageView not showing up on LinearLayout. Probably an Android bug.
    – atedja
    Nov 28, 2011 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.