I am trying to setup a section of a screen with 4 images around each other but there is huge white space between them as per image example:
I would like them all right next to each other. Below is the XML I am using:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageView1"
android:src="@drawable/test1"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageView2"
android:src="@drawable/test"
android:layout_weight="1"/>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageView3"
android:src="@drawable/test1"
android:layout_weight="1"/>
<ImageView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/imageView4"
android:src="@drawable/test"
android:layout_weight="1"/>
</LinearLayout>
I am also trying to get them to the top of the screen but that white space is preventing that.
The images you see dont have any white space at all, the edge of the colors are the edge of the image?
Thanks
You need to set the scaleType
to centerInside
and the adjustViewBounds
to true
like this: (adjust view bounds should get rid of the space you don't want.)
<ImageView
...
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:adjustViewBounds="true" />
@x10sion:For your information,
android:scaleType="centerInside"
is going to center the image inside the container, rather than making the edges match exactly. Reference
android:adjustViewBounds="true"
this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With