I have this code:
<ImageView
android:id="#+id/imageView3"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="#drawable/house1"
android:scaleType="fitXY" />
and I have this code:
<ImageView
android:id="#+id/imageView3"
android:layout_gravity="center"
android:gravity="center"
android:layout_width="300dp"
android:layout_height="300dp"
android:src="#drawable/house1"
android:scaleType="fitXY"
android:adjustViewBounds="true"/>
But I do not see any changes in output of the image.
What exactly does adjustViewBounds do for the image output?
When using adjustViewBounds you need to set either width or height of your image view to wrap content and the other to a fixed value. Then when you set adjustViewBounds to true, Android adjust your image based on the fixed height or width value you've set and keeps aspect ratio. The scale type plays also a role.
Related
I have a chat application like whatsapp. I want to show several images that i have in the internal storage. So the only thing that i know for that image is the path that i can find it.
However, in the xml layout of the image_item i must set the width and height of the imageView.
<ImageView
android:id="#+id/rcvImage"
android:layout_width="280dp"
android:layout_height="280dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="32dp"
android:adjustViewBounds="true"
android:maxWidth="320dp"
android:maxHeight="320dp"
android:minWidth="150dp"
android:minHeight="150dp"
android:scaleType="centerCrop"
android:src="#drawable/default_img"
tools:ignore="ContentDescription" />
How can i set the values so i can have portrait and landscape images, but without making lags in the recyclerview scrolling
You can set wrap_content and also adjustViewBounds
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/test"/>
Also, scaleType can help with the image resize
android:scaleType="fitStart"
https://developer.android.com/reference/android/widget/ImageView.ScaleType
I have a layout like this:
<LinearLayout
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="8dp"
android:gravity="start|center_vertical"
android:orientation="horizontal"
android:layout_weight="0.25">
<ImageView
android:layout_width="wrap_content"
android:layout_height="20dp"
android:background="#drawable/reply_icon"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
/>
</LinearLayout>
I'm trying to get the ImageView to fit its height (20dp) and auto-adjust the width (while keeping its aspect ratio), however, it comes out looking stretched like this:
How can I fix this?
Add two attributes: (android:adjustViewBounds and android:scaleType=) to your ImageView for keep aspect ratio
android:adjustViewBounds="true"
android:scaleType="centerCrop"
Hope this help
I have an image that seems to change its size depending on the parents height, well the parent/parents height. Point is I do not want the image to change size. Is there some way to stop it from thinking for itself?
<ImageView
android:id="#+id/ivSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp"
android:paddingRight="10dp"
android:src="#drawable/img_save"
android:layout_gravity="left"
android:contentDescription="#string/ivSave" />
wrap_content means that the view will resize automatically. To set a fixed size use:
android:layout_width="100dp" and android:layout_height="100dp"
Use 'dp' instead of 'px', because these are device-independent.
try
android:scaleType="centerInside"
<ImageView android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/img_save"
android:scaleType="centerInside">
</ImageView>
click here for more image scale type
I want to define maxHeight for an image that it's adjustViewBounds has been set to true.
in this way adt automatically keeps aspect ratio.
is there any way to gain this approach without keeping aspect ratio?
this is the image, and i want to stretch it from sides, without being displaced:
You can do like this
<ImageView
android:layout_width="100dp"
android:layout_height="400dp"
android:src="#drawable/ic_launcher"
android:scaleType="fitXY"/>
try this
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/your image name"
android:scaleType="fitXY"/>
I think android:scaleType="fitXY" is what you are looking for.
I have added image in android, but it is fitting to middle of the screen, what can I do to set it for full screen?
what is wrap_content and fill parent, I'm not getting how to do this.
This is my code
<ImageView
android:scaleType="fitCenter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_image" android:cropToPadding="false"/>
Try this
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="center"
wrap_content says ImageView to fit image dimension and fill_parent to fit dimension of father layout.
Look for scaleType
<ImageView android:scaleType="fitCenter" />
You may try:
android:scaleType="fitXY"
Read more about ScaleType.