0

Please don't mark this a duplicate, as I am unable to find the solution.

Hi, I am trying to add src image with some background color

Here is what I am doing

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="20dp"
android:background="@drawable/bg_layout_corners"
android:backgroundTint="@color/color_fbfbfa"
android:gravity="center">

<ImageView
    android:id="@+id/iv_dashboard_niggle"
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:layout_centerHorizontal="true"
    android:layout_centerInParent="true"
    android:layout_centerVertical="true"
    android:scaleType="centerInside"
    android:background="@color/colorAccent"
    android:src="@drawable/niggle2_3_3_3" />

</RelativeLayout>

enter image description here

and here is the output I am getting

When I try to decrease the width or height of imageView, the actual image is placing at the center and some border is visible.

I also checked for scaleType="center", this is also not working

Please help me.

joe_inz
  • 998
  • 2
  • 13
  • 30
Poojashree
  • 61
  • 4

3 Answers3

0

The image that you wanted to set in a image view needed to be in the same aspect ratio to fit exactly without applying scaleType...

for example

If you want to set a square image that have height and width ratio 1:1 then ImageView ratio needs to be 1:1

Well but also we have ScaleType if images not according ratio then we can set scale type to match the size of image view by resizing our image

In your case it's completely depend on what you want to show.

If you don't want background border then simply set background color to transparent by using

android:background="@android:color/transparent"

Best way is define ImageView size according aspect ratio if you don't want to use scale type

Ashwini Saini
  • 1,324
  • 11
  • 20
0

Hope this solves your problem.

iv_dashboard_niggle.setScaleType(ImageView.ScaleType.fitXY);
Jatin Bhatia
  • 248
  • 4
  • 15
0

Set wrap_content as height for your relative layout. Then the space will go.

Waseem
  • 439
  • 3
  • 18