Reputation: 3009
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
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>
Upvotes: 1
Views: 3029
Reputation: 15766
Try adding android:adjustViewBounds="true"
to your ImageView
s
Upvotes: 2
Reputation: 300
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.
Upvotes: 3