:)
I am using an ImageView and I display gifs in it. The problem is for example this gif: http://media3.giphy.com/media/110U0ZUA6mPxqE/200.gif has different dimensions than this: http://media0.giphy.com/media/10YsmVhdN1S6wE/200.gif and I display the gifs in a listview. The gif which has more or less the same height and width is shown good. But the gif which has unreasonably different width and heigt shows only a part of the gif..
This is my Item:
<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="match_parent"
android:orientation="horizontal">
<ImageView
android:id="#+id/imageViewGif"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:minWidth="300dp"
android:visibility="visible" />
</LinearLayout>
<ProgressBar
android:id="#+id/progressBarSearchedGif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
</RelativeLayout>
To sum up, the question is how can I show the full gif in my imageview even when the dimensions of the gifs are different.
you can try removing android:scaleType="fitCenter" , and set android:adjustViewBounds="true" to your imageview.
If you always want the entire image to display in an ImageView, you have two choices. You can either stretch it to fit the size of the ImageView with this option:
android:scaleType="fitXY"
Or you can reduce the size of the image to fit the ImageView without changing its aspect ratio:
android:scaleType="centerInside"
Refer to the javadoc for details.
Related
I am developing an android app thap show some photos in a listview.
This is layout for each item in listview.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/exam_page_item_imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"/>
</RelativeLayout>
My listview displays
I want to display imageview that fits the width of device. (fit width only)
Could you give me suggestion or have any idea to resolve this problem ?
Try this :
<ImageView
android:id="#id/imgview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitCenter" />
android:adjustViewBounds = "true"
Will help when your images are larger than the imageview. It will not strech the image but will shrink it.
android:scaleType="fitCenter"
For times when your image is smaller than imageview, it will strech the image to the width of its parent.
Problem: trying to give multi device support screen for a simple layout but in Nexus 6 its creating the problem,means not showing fit.
It's side is cutting down where as per as docs for nexus-6 resolution is 1440*2560 and image should be in drawable-xxxhdpi .so i keep a image with resolution of 1440*2560.
<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="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:id="#+id/imv" />
</RelativeLayout>
if i ll give match_parent so obvious it will stretch the image.
Please help me to get out of it.
Here is screen shots of screen -
http://s10.postimg.org/43od5j5h5/screen_shot_layout.png
Set the width of the Image to fill_parent (you can set margins if you want a bit smaller imageView or you could also just set a fixed width)
Use android:adjustViewBounds to keep aspect ratio
Set height to wrap_content (it will take whatever it takes to maintain aspect ratio)
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/icon"
android:id="#+id/imv"
android:scaleType="fitCenter" />
If you want to fit the image on the imageview, replace android:src with android:background in the ImageView in the xml code.
Try to use these lines of code in the layout
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/icon"
android:scaleType="fitXY"
android:id="#+id/imv" />
My app gets the album cover images from an Internet source. The image dimensions are varying from 200*200 to 400*400, therefore making scrolling necessary on some smaller devices. The layout resource codes and layout view are below.
The ImageView is the view with the red borders.
All I need is to make downloaded image to fit the imageView, so that the users won't have to scroll vertically to see the view below. How can I accomplish that? Thanks in advance...
<LinearLayout
android:id="#+id/llayoutAlbumCover"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:gravity="top|center" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/albumCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="3sp"
android:scaleType="fitCenter"
android:src="#drawable/loading" >
</ImageView>
</FrameLayout>
</LinearLayout>
use imgview.setScaleType(ScaleType.FIT_XY);
Through xml also you use like this
<ImageView
android:id="#+id/albumCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="3sp"
android:scaleType="fitXY"
android:src="#drawable/loading" >
</ImageView>
PS:: I know this is what you wanted, but for images where you care about aspect ratio, this will stretch it out.
You can set scale, for example imageView.setScaleType(ScaleType.fitCenter)
Samples: http://etcodehome.blogspot.com/2011/05/android-imageview-scaletype-samples.html
Using android:scaleType="fitCenter" guarantees at least one axis will be fitted in the view. Use android:scaleType="centerInside" instead. The dimensions will be equal or smaller then your view. For more options please check ImageView.ScaleType
I am working on application which shows images, and I need to create a view which shows big images in a 1:1 aspect ratio.
First, I have thumbnails which are at a 72x72 resolution. I have put them in an ImageView but even if I add the parameters android:width="fill_parent" and android:height="wrap_content", the image would not be not the size of the ImageView but is only centered in the mid.
I tried adding the parameter android:scaleType="centerCrop" which resized the image well horizontally but the height remained the same.
How could I set up my ImageView so that it would be on all devices as width as the parent view and it should also be as height.
I can do this programatically, but I need to be able to do it in XML.
My XML File:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
// The ImageView I am talking about above
<ImageView
android:id="#+id/invitation_imageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="1dp"
android:scaleType="centerCrop"
android:src="#drawable/face_woman_smile" />
<ImageView
android:id="#+id/invitation_avatar_view_1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:src="#drawable/face_woman_smile"
android:scaleType="center"
android:layout_margin="1dp" />
</LinearLayout>
I think you need to add this to your ImageView
android:adjustViewBounds="true"
Use:
android:scaleType="fitXY"
To make image stretch to parent's width while keeping aspect ratio
Set
1- android:layout_width to match_parent
2- layout_height to wrap_content
3- adjustViewBounds to true
Like this:
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/unknown"
android:adjustViewBounds="true" />
Note: This might not render correctly in Preview but would work on runtime.
I usually use android:width="match_parent" and android:height="wrap_content", as you mentioned, but I use android:scaleType for my ImageView layouts.
You can read more about it here.
I use Layout_width="fill_parent" and Layout_height="wrap content". If an image is bigger than the ImageView, it will be downscaled perfectly.
However, I never got it working to upscale smaller images. I tried any combination of ScaleType and "AdjustViewBounds": it always stays in its own size in the middle of the image view. Here is the code...
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_height="wrap_content"
android:background="#drawable/content_bg"
android:orientation="vertical"
android:padding="5dp"
android:layout_width="fill_parent"
android:layout_marginLeft="1px">
<ImageView
android:layout_height="wrap_content"
android:src="#drawable/test"
android:id="#+id/ImageViewTest"
android:layout_width="fill_parent"
android:adjustViewBounds="true"
android:scaleType="center"></ImageView>
</LinearLayout>
I just found a way to make it work.
This works in 2.1(AVD) & 4.1.2(device)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitCenter" />
</LinearLayout>
<LinearLayout
android:layout_height="wrap_content"
uses the original size of the image inside.
Try something bigger or fill_parent
Use android:scaleType="FIT_START" or android:scaleType="FIT_END", to Compute a scale that will maintain the original src aspect ratio, but will also ensure that src fits entirely inside dst (from GoogleDev).
More info:
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
Adding android:scaleType="fitXY" to ur ImageView should stretch the image if the size is small.