ImageView adjustViewBounds not working with fitXY - android

I use the following code to show my button
(Because I need to add the text on the button, so I will not use the ImageButton)
<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">
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/bottom001"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
</RelativeLayout>
But the ImageView will have some empty area in the View
I think "fitXY" will fill the View, but it didn't
How can I do in this case?
Thanks for your help :)

set android:layout_width="wrap_content" And Use LinearLayout
Finally
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/test"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
For details please read android-imageview-scaletype-samples
FIT_XY
Scale the image using FILL.Stretch the picture inside the available width and height, disgarding the aspect ratio.

Related

Display an image with height 'matchparent' and also keep the aspectratio

I want to display an image in Imageview with full height and also keep the aspect ratio of the image. To view the remaining part of the image, I want horizontal scrolling on that image. Please share the idea behind it?
As mentioned by ResolutioN, adjustViewBounds does the trick, but fitXY is not necessary. Just wrap your ImageView inside a HorizontalScrollView
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:src="#drawable/image" />
</HorizontalScrollView>
Combine adjustViewBound and scaleType="fitXY" to achieve your goal. This will keep the aspect ratio of the image. Like this:
<ImageView
android:scaleType="fitXY"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
Hope this code helps you:
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/horizontalScrollView"
>
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
</HorizontalScrollView>

Scale my item image to fit the screen properly

So I got a problem scaling my image to fit my home screen appropriately.
Here are some screenshots.
Height problem
Width problem
I want to achieve something like this
XML Item code
<?xml version="1.0" encoding="utf-8"?>
<com.inthessaloniki.cityguide.view.SelectorRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/fragment_poi_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:listSelector="#drawable/selector_clickable_item_bg_inverse">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ImageView
android:id="#+id/fragment_poi_list_item_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"/>
</RelativeLayout>
</com.inthessaloniki.cityguide.view.SelectorRelativeLayout>
I want the images to match the parent width but scale their heigth accordingly.
The scaleType="fitXY" forces image to fix to screen and does not keep aspect ratio.
Try this instead
<ImageView
android:id="#+id/fragment_poi_list_item_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:adjustViewBounds="true"/>
In the end I found out a solution.
Here it is in case someone had the same problem.
I used scaleY and padding to fit the images accordingly.
<ImageView
android:id="#+id/fragment_poi_list_item_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="7dp"
android:paddingBottom="7dp"
android:scaleType="fitXY"
android:scaleY="1.25"/>

Resize LinearLayout or RelativeLayout after resizing ImageView inside it

I have to put an ImageView inside a RelativeLayout. Just like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imagen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:src="#drawable/image1"/>
</RelativeLayout>
I know that this image will be resized in some devices because it would be too big for the device's screen. The remaining resized layout is something like this, notice the gray area around the image, wich is the original RelativeLayout BEFORE resizing, I think!
How can I remove that remaining space? Thanks!
Try this
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/imagen"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/image1"/>
</RelativeLayout>

Imageview not matching the width of Linearlayout

I have a layout in which a linearlayout contains imageview as its direct child. I want to fit the width of this imageview so that it spans horizontally to match the size of the parent which will take the width of the whole screen.
How can I do that? This is what i've done so far:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/linearLayout"
>
<ImageView
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="0dp"
android:src="#drawable/policemen_salute"
android:id="#+id/banner"
/>
</LinearLayout>
</RelativeLayout>
It looks like this
Thanks!
Add the 'scaletype' attribute:
<ImageView
android:layout_width="fill_parent"
android:layout_height="100dp"
android:scaleType="fitXY"
android:layout_margin="0dp"
android:src="#drawable/policemen_salute"
android:id="#+id/banner"/>
See
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
You have to use a scaleType to scale correctly the image.
try your ImageView like this:
<ImageView
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="0dp"
android:src="#drawable/policemen_salute"
android:id="#+id/banner"
android:scaleType="centerCrop"/>
You can use android Scaletype Property .
android:scaleType="fitXY"
Then set android adjustviewbounds true from XML .Try this way I hope it will helps you.
If you wish to scale your image, you might want to add
android:scaleType="fitXY"
(Scale in X and Y independently, so that src matches dst exactly)
to your ImageView
<ImageView
android:layout_width="fill_parent"
android:layout_height="100dp"
android:layout_margin="0dp"
android:scaleType="fitXY"
android:src="#drawable/policemen_salute"
android:id="#+id/banner"
/>

android layout large image

I have a large image myImage.png (its dims are 1536 x 784):
I want this image to be placed at the bottom of my layout scaled uniformly and fitting the width:
Layout is
<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" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/myImage"
android:adjustViewBounds="true"
android:layout_alignParentBottom="true"
android:scaleType="fitCenter" >
</ImageView>
</RelativeLayout>
I've tried dozens of combinations for layout_width, layout_height, adjustViewBounds and scaleType and nothing helped: it always looks as follows:
Help me please.
As someone says, use src instead of background:
<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" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/myImage"
android:adjustViewBounds="true"
android:layout_alignParentBottom="true"
android:scaleType="fitCenter" >
</ImageView>
</RelativeLayout>
You are using an ImageView. ImageViews use the src attribute to indicate which image to use and to apply the scaleType to.
background, is, as name suggests, merely a background attribute, made to be displayed on that whole background thing.
try this:
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/myImage"
android:adjustViewBounds="true"
android:layout_alignParentBottom="true"
android:scaleType="fitcenter" >
</ImageView>

Categories

Resources