Remove padding created from ImageView after scaling down LayoutParams

1k Views Asked by At

In my relative layout, I want two images to display on extreme right bottom and left bottom of the screen. I can see padding on the edges of the screen after scaling the width and height of the imageview to one third. I want padding to be removed and images should come to extreme right bottom and left bottom

Is there anything

Here is activity xml and java code

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity" >


             <ImageView
            android:id="@+id/basket2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_alignParentBottom="true"
            android:adjustViewBounds="true" 
            android:src="@drawable/basketclose2" />

          <ImageView
              android:id="@+id/basket1"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_alignParentBottom="true"
              android:layout_alignParentLeft="true"
              android:adjustViewBounds="true"
              android:src="@drawable/basketclose2" />

Java Code:

        leftBasket.getLayoutParams().width = width/3;
        leftBasket.getLayoutParams().height = height/3;


        rightBasket.getLayoutParams().width = width/3;
        rightBasket.getLayoutParams().height = height/3;
5

There are 5 best solutions below

0
On

So remove padding from your layout

android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
0
On

remove :

  android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"

from relative layout.

0
On

you have mentioned padding in layout that is the issue just remove it

0
On

remove the paddings in the RelativeLayout.

0
On

write like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >


         <ImageView
        android:id="@+id/basket2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentBottom="true"
        android:adjustViewBounds="true" 
        android:src="@drawable/basketclose2" />

      <ImageView
          android:id="@+id/basket1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:layout_alignParentBottom="true"
          android:layout_alignParentLeft="true"
          android:adjustViewBounds="true"
          android:src="@drawable/basketclose2" />

</RelativeLayout>