Jezer Crespo
Jezer Crespo

Reputation: 2172

Android: how to get rid of extra space in ImageView's bounding box

I'm trying to merge a two ImageViews to make them look like as one, but there's bounding box that prevents them to be totally next to each other.

ImageViews bounding box

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_margin="0dp"
    android:padding="0dp"
    android:src="@drawable/plant" />

<ImageView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_margin="0dp"
    android:padding="0dp"
    android:src="@drawable/red_base" />

I tried setting padding and margin to 0 but it doesn't do it

Note: those two pictures that I used don't have a blank space around them.

Thanks!

Upvotes: 0

Views: 719

Answers (5)

Ilya Gazman
Ilya Gazman

Reputation: 32221

Push them to relative layout and place them manually, some thing like this:

<RelativeLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content">

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_alignParentLeft="true"
            android:layout_marginTop="180dp"
            android:src="@drawable/plant" />

        <ImageView
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_alignParentTop="true"
            android:layout_alignParentLeft="true"
            android:src="@drawable/red_base" />
</RelativeLayout>

Upvotes: 0

Jitender Dev
Jitender Dev

Reputation: 6925

Set top margin for the below image as -5 dp i.e. android:layout_marginTop="-5dp"

Below is your updated code

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:src="@drawable/icon" />

    <ImageView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_marginTop="-25dp"
        android:src="@drawable/icon" />

</LinearLayout>

*Updated margin to -25dp, just to observe the change.

Upvotes: 0

Chintan Soni
Chintan Soni

Reputation: 25267

You need to set the scaleType property of the ImageView.

Upvotes: 0

balaji koduri
balaji koduri

Reputation: 1321

in android gives some default padding 8dp for view:

try this:

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_margin="0dp"
    android:padding="-4dp"
    android:src="@drawable/plant" />

<ImageView
    android:layout_width="200dp"
    android:layout_height="200dp"
    android:layout_margin="0dp"
    android:padding="-4dp"
    android:src="@drawable/red_base" />

Upvotes: 1

Sush
Sush

Reputation: 3874

set below two properties
android:adjustViewBounds="true"
android:scaleType="fitEnd"

Upvotes: 1

Related Questions