Can you help me to configure my layout? I don't achieve what I'm looking for:
I've put the imageview background to red for explain what I want:
The image's width is smaller than the layout width. I'd like the image grow proportionally keeping its aspect ratio until reach the aspect at the first image (I modified it manually with photoshop) but when setting width="fill_parent" the result is the second image and setting both width and height to "fill_parent" the result is the third image.
I tried to combine with ScaleType with no success
How can I achieve the first option? Thanks
android:scaleType. Controls how the image should be resized or moved to match the size of this ImageView. android:src. Sets a drawable as the content of this ImageView.
ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android. graphics.
Use android:adjustViewBounds=true
attr in xml for ImageView
This question is solved here by extending the ImageView class.
Android ImageView adjusting parent's height and fitting width
I created a sample. It works for me. Here is the xml layout file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView android:src="@drawable/hydrangeas"
android:layout_height="wrap_content" android:id="@+id/imageView1"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:background="@android:color/white"
android:layout_width="wrap_content"/>
</LinearLayout>
It works for fitCenter
too. Have a look at the snapshot.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With