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>
Related
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 the image looks too small on screen, how to scale it to fit the screen? wrap_content does not seem to work
<RelativeLayout
android:id="#+id/layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ImageView
android:layout_alignParentTop="true"
android:layout_marginTop="100dip"
android:id="#+id/imageview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/splash_screen"/>
<ProgressBar
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dip"
android:id="#+id/progressbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
Add the following attribute to your ImageView to get it to scale as you like (will fill the size of your ImageView):
android:scaleType="fitXY"
I would actually change your width attribute as well. Your final XML could look like this:
<ImageView
android:layout_alignParentTop="true"
android:layout_marginTop="100dip"
android:id="#+id/imageview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="#drawable/splash_screen"/>
After testing, the following works:
<ImageView
android:layout_alignParentTop="true"
android:layout_marginTop="100dip"
android:id="#+id/imageview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="fitXY"
android:src="#drawable/splash_screen"/>
it's your image issue,may be the image contains unnecessarily enlarged background,crop the image,remove unnecessary background and then it will be solved
I have this 9-patch picture "Imageview3"
I want to add in my activity. I want the red arms to matchs perfecty with the borders of the screen.
But when I do SCALE:fitXy here is what I obtain
so as you can seem it doesn't work, I tried all the scales, I tried to stretch the image but it never fits.
Here is my code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<FrameLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="324dp"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:paddingTop="150dp"
android:paddingRight="0dp"
android:src="#drawable/diviseur" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="407dp"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:src="#drawable/a1"
android:visibility="visible" />
</FrameLayout>
</LinearLayout>
thanks for the help
Remove android:scaleType="fitXY" and keep android:layout_width="match_parent". Try it.
Make sure your actual image doesn't have a white border around it. As in, make sure the arms are at the very end of your image.
Instead of using android:src="#drawable/diviseur", try using android:background="#drawable/diviseur". And also consider using android:layout_weight="1" attribute.
Try this
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/banner"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:adjustViewBounds="true"
android:src="#drawable/foo"
/>
the imageview takes extra [black] space and i dont know why
ok this imageview should wrap content but instead..
photo explains the problem
this is the code
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/map"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/map" /><ImageView
android:id="#+id/blxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="-20dp"
android:src="#drawable/photo" />
<ImageView
android:id="#+id/blxx"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="#drawable/blxx" />
</LinearLayout>
</ScrollView>
Try the below:
android:adjustViewBounds="true"
This will remove the extra padded space
first possible reason for your problem:
sometimes when the image is too small, it can't scratch anymore then some limit. after that limit - what happens is what you see - blank space claimed by the imageView where additional scratch of the image was expected. I advice you to take larger picture (with bigger resolution)
Second possible reason:
add to your imageView properties on the xml file the following attribute:
android:scaleType="fitXY"
android:layout_gravity="center"
Above line is centering the image to fit inside your ImageView. Try without it. If not, set gravity to "fill" and try again.
Also remove one of the duplicates of blxx as noted.
hope this ll help you
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:layout_gravity="center">
<ImageView
android:id="#+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_content"
android:src="#drawable/map" />
</LinearLayout>
</ScrollView>
I have a background image that I would like to 1) fill the vertical space, regardless of whether the image's width is greater than the width of the parent, and 2) align the right edge of the image with the right edge of the parent.
Currently scaleType="centerCrop" is giving me (1) but not (2); it centers the image horizontally. Does anyone know how to get it to right-align? Thanks!
EDIT: Tried adding android:layout_alignParentRight="true" to both the relative layout and image view, with no effect.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_gravity="center" >
<ImageView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/bg"/>
<LinearLayout
android:id="#+id/fg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
...
You can use
android:layout_alignParentRight="true"
for the Imageview
add these attributes
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
<ImageView
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/backg_carbon" >
</ImageView>
I think your issue is that the viewbounds do not adjust to the size of the actual image and fill up the width for some reason. Best thing is to check if setting
android:adjustViewBounds to true helps (with the gravity to right of course).
<ImageView android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:adjustViewBounds="true" //This is the added line.
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="#drawable/bg"/>