1

I used LinearLayout to stack 4 images horizontally and it works well except for the height. It seems that the linearlayout is not properly wrapping its content. If I don't set the images' scale type to fitStart, they will be centered inside the linearlayout.

Here is my layout below:

linearlayout

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top"
    android:orientation="horizontal"
    android:weightSum="4"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@drawable/header1"
        android:layout_weight="1"
        android:scaleType="fitStart" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView2"
        android:layout_gravity="center_vertical"
        android:src="@drawable/header2"
        android:layout_weight="1"
        android:scaleType="fitStart" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView3"
        android:layout_gravity="center_vertical"
        android:src="@drawable/header3color"
        android:layout_weight="1"
        android:scaleType="fitStart" />

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/imageView4"
        android:src="@drawable/header4"
        android:layout_weight="1"
        android:scaleType="fitStart" />
</LinearLayout>
Blo
  • 11,775
  • 5
  • 43
  • 95
dgzz
  • 2,889
  • 6
  • 32
  • 55

3 Answers3

3

Try setting the adjustViewBounds attribute to true for those images. http://developer.android.com/reference/android/widget/ImageView.html#attr_android:adjustViewBounds

That should take care of that extra space you have and the LinearLayout should wrap_content correctly.

Steven Roberts
  • 304
  • 1
  • 3
  • 14
2

Try adding android:adjustViewBounds="true" to your ImageViews

James McCracken
  • 14,870
  • 5
  • 51
  • 61
-1
android:adjustViewBounds="true" to be set in your imageview's
Muthuraja
  • 551
  • 5
  • 12