Android: 9-patch image not stretching as expected - android

The actual image is this:
the red boxex are where i made 1 px black likes. Even the preview shows fine. So no problem with 9-patch
but the image i get for the following layout is:
<ImageView
android:id="#+id/image_landing"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:background="#drawable/loginheader"
android:contentDescription="#string/login_header"
/>
I Expected, the logo to be on the left and black dots on the right and the rest of the space between them is filled with grey color i selected on the top
Thank You

Is your ImageView really bigger than your 9patch?
If not, you need to change scaleType as defaut is FIT_CENTER.
Use android:scaleType="fitXY" or android:adjustViewBounds="true".

It looks like your 9 patch is larger than the ImageView that you are trying to put it in. Try setting the ImageView to wrap_content to see if it fixes the problem. If it does, try making the 9 patch smaller, the ImageView bigger or set the scaleType as pcans mentioned.

Related

Transparent image background is showing on ImageButton

I have an image (picture 1) that has a transparent area around it that extends above and below the image itself (picture 2). When I add this image as an ImageButton in my xml and use wrap_content, that transparent area in picture 2 is becoming part of the button rather than just the button itself (picture 1). Picture 3 is the result. Does anyone know how to solve this?
Here's my XML:
<ImageButton
android:id="#+id/resume_button"
android:src="#drawable/disabled_resume_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/new_checklist"
android:layout_centerHorizontal="true"
/>
Do this :
<ImageButton
android:id="#+id/resume_button"
android:background="#drawable/disabled_resume_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/new_checklist"
android:layout_centerHorizontal="true"
/>
the transparent area around your image, if its part of your image, contributes to the actual width and height of the image, imagine if the transparent part of the image was a coloured area rather than a transparent area and you can visulise how it would be part of your image, even though its transparent it is taking up an area that contributes to the height and width of the image
"wrap_content" attribute just set the height of yout button to the height of yout image.
If you want to keep only the colored part of your image, just resize it! ;)

How to auto center crop ImageView Android?

I made a listView images. My goal that each item of my listView have the same height of 100dp. I encounter a problem that my imageView is resized automatically, but does not take the entire space of the parent.
Here is my current result and objectif result :
Does anyone know the option to add to make crop center automatically?
I am not sure if I understood correctly. It must be either of the two, that you want, I guess.
In your image view set the attribute
android:scaleType="fitXY"
to fit the ImageView completely.
You can choose
android:scaleType="centerCrop"
to crop Center.
i know it's late but maybe it would be helpful for someone coming on this question page by using android:scaleType="centerCrop" image is centered but it is cropped from all sides so it would be better to use this property instead that is fitCenter and with this use another property too to maintain the aspect ratio
android:adjustViewBounds="true"
android:scaleType="fitCenter"
Are you aware of the cropping options on ImageView?
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
You will just apply these as an attribute in your XML:
like:
android:scaleType="centerCrop"
in java: imageView.setScaleType(ScaleType.FIT_XY);

Handle ImageView pictures in Android

i have a question about pictures in an ImageView in Android.
My problem is, that the pic i wanna show in my ImageView seems too big for my smartphone screen. Therefore it is not on the place i set in the xml...
Here is a pic that you know what i mean: http://www10.pic-upload.de/31.10.12/iuebxzkvr3e.png
The grey area is my Banner which should be located on top of my activity...
If i scale the pic, it should work (the smaller, the higher till it fits), but i think other smartphones with a different resolution should have the same problem again with my app..
Here is my XML:
<ImageView android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/ivBanner"
android:src="#drawable/banner"/>
Nothing special.
thanks in advance
In your layout you should set its height and width to absolute dp values:
Here is a px to dp converter:
http://labs.skinkers.com/content/android_dp_px_calculator/
That solved the problem for me, for every screen size you need a different values(hdpi/xhdpi).
you can set scaleType for ImageView to fitXY, or centerCrop
android:scaleType = "fitXY"

9patch stretches vertically, but does not horizontally

I created a 9patch image and somehow it does only stretch vertically.
I tried other 9-patch images, but they have the same effect, whyle they work in other situations. So the 9patch should be fine I think.
This is my XML code:
..
<ImageView
android:id="#+id/bottombar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:contentDescription="#string/app_name"
android:src="#drawable/bar" />
</RelativeLayout>
Anybody had the same issue and know how to solve it?
Thanks
If you are sure that the height of your View is really taller than the current image (as the others have suggested) then you should change your ImageViews scaleType. The default is FIT_CENTER which does not stretch the image, you should set it to FIT_XY.
Also you may try to set your 9-png file as the background of your ImageView not as the src and I think this will also stretch the file.
Did you add a black dot to the top dead center as well as the left side center?
The issue may be in layout_width="match_parent" you have mentioned width to match parent this may be the reason of 9 patch image to stretch vertically. But for height you have written height="wrap_content" So it doesnt stretch in height
You have wrap_content specified for the height. Are you sure the content is tall enough to make the image stretch?

Trimming ImageView in Android

I have an image which is 450px square below some text in a linear layout and wanted it to fill the width of the device, which I done by using;
ImageView android:id="#+id/my_image_container"
android:src="#drawable/my_image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/orange"
android:scaleType="fitStart"
This has worked in a fashion, but the ImageView element fills the rest of the screen and any elements placed under do not show.
Does anyone know of a way to trim the bottom of the space that the ImageView uses.
Hopefully this image can explain it better - I want to crop the empty area under the image (orange background).
I recommend you to use a RelativeLayout instead of a LinearLayout. You can then use android:layout_above="" and android:layout_below="" to ensure that you get the layout you want.

Categories

Resources