Size of Widget Image - android

I have an image that I do not want to scale, I am using fitStart. What size do I need to make it to ensure that it covers a 4x2 widget? I currently have an image that is 1024x768 and it doesn't cover.
UPDATE:
Here is the xml and screen shot:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/widget_bg_rl"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/widget_bg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitStart" />
<LinearLayout
android:id="#+id/current_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:weightSum="8">
<RelativeLayout
android:id="#+id/city_time_rl"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2.5"
android:background="#drawable/rounded_corners_top">
<TextView
android:id="#+id/city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="MECHANICSBURG"
android:textSize="16dp"
android:textColor="#color/dk_blue"
/>

You're using fitStart, which maintains the image aspect ratio, and ensures that one dimension (height, in this case) fits exactly. It sounds like you want one of these two:
If you want to fill the space, showing the entire image (and stretching it as necessary), use fitXY.
If you want to fill the space, maintaining the image's aspect ratio (and cropping it as necessary), use centerCrop.

Related

Android: Set size of ImageView (GIF) to dimensions of source

:)
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.

Image taking Double the space in imageView in Android

i have put an image in Imageview, but it is taking double the space. There is large gap between the image and textview beneath it. how can i set the image to use the height as per image?
My layout is as follows:
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center" android:padding="5dp" >
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#drawable/babyfa"
android:scaleType="fitStart"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/whatis"
/>
I have attached the imge, the red line represents the extra space the imageview is taking. kindly advise.Image
This is likely being caused by android:scaletype="fitStart". Try removing this from your XML. See this helpful guide for the effects of different scaletype properties (fitStart is at the bottom).
Edit: Try also setting android:adjustViewBounds="true". This will hopefully force the ImageView to preserve the image's aspect ratio.

How to Fit the Downloaded Images into the ImageView (to Eliminate the Need for Scrolling)

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

Android List View Image Issue

I have Created a Listview, and I am trying to add Images to some entries in the Listview. However when doing that I seem to get strange results, the Image appears much smaller than it should. Despite the fact that I have set its Width to Fill_Parent. Here is the XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
...
<ImageView
android:id="#+id/webImage"
android:layout_below="#id/link"
android:layout_toLeftOf="#+id/ll"
android:layout_alignBottom="#id/ll"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="8dp" />
<HorizontalScrollView
android:id="#+id/sv"
android:layout_marginLeft="6dp"
android:layout_marginBottom="3dp"
android:layout_below="#id/webImage"
android:layout_toLeftOf="#+id/ll"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:gravity="center_vertical"
android:id="#+id/tag_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</HorizontalScrollView>
<LinearLayout
android:layout_margin="4dp"
android:layout_alignParentRight="true"
android:id="#+id/ll"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="fill_parent">
...
</LinearLayout>
</RelativeLayout>
Here is the Result:
As you can see, the images are not showing up as intended and some are smaller than others. The Images should span across the entire screen.
You should use ScaleType for ImageView.ImageView is comes with different configuration options to support different scaleTypes. scaleType options are used for scaling the bounds of an image to the bounds of this view. Below are the listed scaleType configuration properties supported.
CENTER
CENTER_CROP
CENTER_INSIDE
FIT_CENTER
FIT_END
FIT_START
FIT_XY
MATRIX
Check here for more details
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

keep aspect ratio of background image (android)

I have a background image which should be scaled on the height, but keep its aspect ratio. I tried it with this code:
<ImageView
android:id="#+id/iv_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/bg" />
This works on phones in portrait mode, but when I test it on a tablet (default landscape), it scales the width and cuts the image on top and bottom. Is this because of the xml code or because of the landscape?
Try something like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/background_image"/>
<!-- Your other views -->
</RelativeLayout>

Categories

Resources