1

I'm trying to remove padding from my ImageView but it always leaves a padding of 4 on all sides. Any help will be appreciated. This is my code.

newmenuitem.xml (Note: newListAvatarSizeX = 190 and newListAvatarSizeY = 150 )

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingRight="10dp"
android:id="@+id/layout">
<ImageView
    android:id="@+id/avatar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:maxWidth="?attr/newlistAvatarSizeX"
    android:maxHeight="?attr/newlistAvatarSizeY"
    android:adjustViewBounds="true"
    android:padding="0dp"
    android:layout_margin="0dp"
    />
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/avatar"
    android:layout_toLeftOf="@id/viewprofile"
    android:layout_alignParentBottom="true"
    android:gravity="left|bottom"
    android:orientation="vertical"
    android:paddingLeft="5dp"
    android:paddingRight="10dp"

    >
    <TextView
        android:id="@+id/toptext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:singleLine="false"
        android:gravity="bottom"
        style="?listContactsPrimaryText"
    />

</LinearLayout>
<ImageView
    android:id="@+id/arrow"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:layout_centerVertical="true"
    android:adjustViewBounds="true"
    android:src="@drawable/arrowbutton"
    />

code

    final ImageView iv = (ImageView) v.findViewById(R.id.avatar);
    Bitmap bm = ((BitmapDrawable) getResources().getDrawable(R.drawable.image_none)).getBitmap();
    Matrix matrix = new Matrix();
    matrix.postScale(190 / bm.getWidth(), 150 / bm.getHeight());
    final Bitmap bmf = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), matrix, true);
    runOnUiThread(new Runnable() 
    {
        public void run() 
        {
            iv.setImageBitmap(bmf);
        }
    });

As you can see from hierarchy viewer it still has padding of 4.

enter image description here

EDIT:

I have made a temporary fix by adding this.

   android:layout_marginBottom="-4dp"
   android:layout_marginTop="-4dp"
   android:layout_marginLeft="-4dp"
   android:layout_marginRight="-4dp"

This is not good practice, but at least it works. Would really be awesome if someone out there might know why this happens.

Rikus Louw
  • 78
  • 7
  • try to set `android:layout_padding="0"` for the `avatar` – ivan.mylyanyk May 21 '14 at 07:56
  • I've never heard of `android:layout_padding`, you sure you don't mean `android:padding`? I get an error trying to build with `android:layout_padding` – Rikus Louw May 21 '14 at 08:21
  • Yey, my mistake, sorry. On the other hand, maybe `android:layout_height="fill_parent"` `android:layout_width="fill_parent"` will solve this issue? – ivan.mylyanyk May 22 '14 at 11:07
  • Also, remember, `adjustViewBounds` only works when your source image is larger than the place for it. – ivan.mylyanyk May 22 '14 at 11:09
  • possible duplicate of [Unwanted padding around an ImageView](http://stackoverflow.com/questions/5830503/unwanted-padding-around-an-imageview) – ivan.mylyanyk May 22 '14 at 11:10
  • I've checked that question out before, I have had no luck with `adjustViewBounds` even when the source bitmap is scaled to astronomical large sizes and the imageview has `android:layout_width="wrap_content"`. Also, `android:layout_height="fill_parent"` as well as `android:layout_width="fill_parent"` creates an undesired effect of the image filling the screen. – Rikus Louw May 22 '14 at 11:34

1 Answers1

0

try this,

<ImageView
    android:id="@+id/avatar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:maxWidth="?attr/newlistAvatarSizeX"
    android:maxHeight="?attr/newlistAvatarSizeY"
    android:adjustViewBounds="true"
    android:scaleType="fitXY"
    android:padding="0dp"
    android:layout_margin="0dp"
    />

this may help you

Akash Moradiya
  • 3,318
  • 1
  • 14
  • 19