I am really confused about this.I have set the background color of the whole screen to blue and I have a framelyout with image view under it. When I choose playingcard drawable as its source then the white background of the playing card is becoming blue and the image is not clear. Why is this happening?
Below is what the screen is looking like:
.
My image is :
:
And here is Part of the XML code:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#0000FF" >
<FrameLayout
android:id="#+id/frameLayoutBottom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" >
<ImageView
android:id="#+id/ivBottom2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:src="#drawable/c11"/>
I don't want to set the background of image to white as I am using padding and I don't want the padding to be white.. The weird thing is that if I use other images that are say red then it shows perfectly, it is just when I use playing cards (I have 52 cards), it is showing like that
Any help please?
Thank you.
Your image has transparent pixels. Use an image editor to convert them to white.
Alternatively, you can specify a margin instead of padding and setBackgroundColor() on your ImageView.
Related
I'm trying to set 1080*1920 image in imageview but it showing white space left and right side. It showing same in all device having resolution of 480*800,720*1280,768*1280,1080*1920,1440*2560. Please check attached image Also, i tried to set android:adjustViewBounds="true" but it didn't work if i set android:scaleType="fitXY" image is streched. Please help me with some solution as i'm trying all possible way but not worked till now.
This is xml layout code :
<?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">
<ImageView
android:id="#+id/img_gallery1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="#drawable/atest"
android:scaleType="fitXY" --> iF i use fitXY then image is streched
android:visibility="visible" />
</RelativeLayout>
Try:
android:layout_width="wrap_content"
or:
android:layout_width="match_parent"
also make sure whichever container you have the imageview inside is able to fill the full screen.
The resolution you mentioned i.e 1920x1080 is ideally a landscape resolution.
So if you intend to put the image in portrait mode, then try changing the resolution of image to 1080x1920.
Also, as Philip said, make sure the imageview's container is able to fill the screen.
I'm using this to crop an image and then i load it to this imageView:
<RelativeLayout
android:id="#+id/activity_edit_image_relative_layout_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true">
<ImageView
android:id="#+id/activity_edit_image_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff2299"
android:scaleType="fitCenter"
android:src="#drawable/phone" />
</RelativeLayout>
the color i'm giving to the background of the image view is pink ( so it will be easy to spot) and the relative layout will act as the view group and i will add other views to it at run time.
the pink background must only appear for the images that have transparent background (png files) like this (this picture is not cropped)
but when i crop an image and load it to the image view i get this
the pink background must not appear. the issue is i'm trying to figure out where on the image is the user taping (overloading onTouch for the imageView) now when i tap on the pink area around the Alien it tells me that i'm tapping the image which is not correct. whats the issue?
Add the following property to your ImageView:
android:adjustViewBounds="true"
I have a textview which has to use a 9-patch drawable as the background. But the 9-patch drawable has left and right paddings which make the background image not stretch properly to cover the whole text. I tried resetting the paddings for the textview itself but it doesn't fix the problem.
Would anyone have any idea how to make it work?
Thanks.
The black lines on the left and top defines the stretchable are, and those on the right and bottom marks the "content" area in a 9-patch image.
So, if you don't want padding means you want a full-length content area. You should mark full-width content area by drawing a full-length line at the bottom and right of the 9patch image.
In this image, the black lines on the right and bottom represent the content area. You can see the preview on the right side, and notice the content area in light blue color. You can fill the content area by extending the bottom and right lines.
Editing 9-patch file is not a good idea, because this method may deform the background image.
I used a trick to handle this:
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<View
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView"
android:layout_alignTop="#+id/textView"
android:background="#drawable/your_9_patch_image"/>
<TextView
android:id="#+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="a custom text!"/>
</RelativeLayout>
I have set the 9-patch background drawable for a View behind my TextView in a RelativeLayout. So the there is no unwanted padding :)
Theoretically you cant really change the padding of 9 patch image programatically.
So you have two options:
1) Have several 9 patch images in your drawable folder for each resolution: drawable-hdpi, drawable-xhdpi etc
2) Embed a inner layout:
<RelativeLayout
android:background="#drawable/nine_patch_image_without_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_margin="10dp" // Your padding goes here
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:text="How you doing"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
It worked for me. I use the second options as it is simpler and quicker to use :)
I trying to create a full screen Imagebutton. But i kept getting grey border ard it.
<ImageButton
android:id="#+id/StartButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/startscreen" />
I have try stretch the pic to full screen on eclipse but there still show a grey border around the picture.
I was wondering is that due to the resolution of my setting or the picture resolution. I am working on a galaxy note.
this should remove the grey border
<ImageButton
android:id="#+id/StartButton"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="#drawable/startscreen"
android:background="#000000"/>
The idea of #Proxy32 is probably the best one. Alternatively don't use the android:src attribute but the android:background. You can also use a simple Button instead with the background set to your drawable and leave the text out.
I've got following 9patch, which I got thanks to nice people who answered my previous question:
I use it for background in relative layout and TextView and got following.
Thats for RelativeLayout:
<RelativeLayout
android:id="#+id/relativeHeader"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android: background="#drawable/cap_stack">
And for TextView:
<TextView
android:paddingTop="5dp"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="22dp"
android:background="#drawable/cap_stack"
android:textStyle="bold"
android:textColor="#FFFFFF"/>
As you can see, I got 1px wide line visible in both cases. And in case of TextView text is not placed in the center vertical. How can I fix it(is it drawable problem or xml)? Will appreciate any help
You shouldn't have a solid border all the way around. The top and left borders define the stretch areas (you only need one pixel on the top for stretching, and you want JUST the gradient to stretch on the vertical axis). The bottom and right borders define the content area, so you want to leave some padding as well. The four corner pixels should never be filled.
Try this one:
or this one:
try this for your textview, the problem is your layout_height You are wanting the textSize attribute instead. Also, notice I used the SP unit instead of DP as that is what the docs recommend for text size values. I hope this helps!
<TextView
android:paddingTop="5dp"
android:gravity="center_vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textSize="22sp"
android:background="#drawable/cap_stack"
android:textStyle="bold"
android:textColor="#FFFFFF"/>
Did you named your image as cap_stack.9.png? It seems android is not processing it as 9patch.
android:gravity="center_vertical" works with LinearLayout Only , Use Layout_centerVertical=true for relativeLayout .
and that lines on border seems part of your image , not seeing any other possibility //////so rechecking image once might be helpful .