1

I want that my image size is exactly the size of parent element

I already use this "android:adjustViewBounds="true"" but its not working. I try many times but fail

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight=".6">

        <ViewFlipper
            android:id="@+id/viewflipper"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:autoStart="true"
            android:flipInterval="2000" >

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:adjustViewBounds="true"
            android:src="@drawable/ic_launcher_background" />

        <ImageView
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:src="@drawable/background" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/background" />

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/background" />
    </ViewFlipper>
    </RelativeLayout>
waqas ahmad
  • 72
  • 1
  • 1
  • 9
  • You need to add the 'scaleType' attribute to your layout: take a look at ::https://proandroiddev.com/a-guide-for-android-imageview-scaletype-and-adjustviewbounds-64a1e4a35503 – Barns Jul 18 '19 at 22:49
  • I will recommend using Picasso lib, fast and easy! Ref: https://stackoverflow.com/questions/30134438/picasso-crop-to-a-view][1] – Lazy boy Jul 19 '19 at 08:54
  • thank you for new knownlege – waqas ahmad Jul 20 '19 at 16:45

1 Answers1

0

Try combine your ImageView with scaleType and adjustViewBounds like this:

         <ImageView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher_background" />

You can use fitXY | centerCrop | fitCenter and others

See more options for scaleType here:

https://developer.android.com/reference/android/widget/ImageView.ScaleType