As you can see from the screenshot below, the "titlebar" is getting these ugly banding lines across the areas with text that extend the entire width of the screen. It's even more noticeable on a real device.
Is there any way to work around this?
From Android Developers: Widget Design Guidelines:
In some cases, devices have low pixel
depths that can cause visual banding
and dithering issues. To solve this,
application developers should pass
assets through a "proxy" drawable
defined as XML:. This technique
references the original artwork, in
this case "background.9.png", and
instructs the device to dither it as
needed.
EDIT:
Example source. This is an xml file in your res/drawables directory:
<?xml version="1.0" encoding="UTF-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/title_bar_medium"
android:dither="true" />
Add android:tileMode="repeat" in this code, like this -
<?xml version="1.0" encoding="UTF-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/b1"
android:tileMode="repeat"
android:dither="true" />
Reason is, on some devices it still stretches the image and it looks pretty bad, check this
Reference here
Related
This feels like a silly question, but i'm still a bit of a noob so....
I'm trying to get my EditText to look like this:
And it works fine on most devices, using this as a background for the editText:
<?xml version="1.0" encoding="utf-8"?>
<!-- res/drawable/rounded_button.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" android:padding="10dp">
<solid android:color="#color/colorTextfield"/>
<corners
android:bottomRightRadius="40dp"
android:bottomLeftRadius="40dp"
android:topLeftRadius="40dp"
android:topRightRadius="40dp"/>
</shape>
However, on some devices (I have an old, low-res testing device here) I get this instead:
Note how the edges are super stretched. It really doesn't look nice. I'm guessing the one solution is to make a style file especially for low-res devices (I'll try that in the meantime), but I was wondering if there was a better way to do this, without having multiple files in which I need to guess what the radius should be for each res. I only have a limited amount of testing devices, and I'm worried I get it wrong.
I am creating a splash screen for android using drawable xml, and my
back_splash.xml looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#android:color/white"/>
<item>
<bitmap android:gravity="center" android:src="#drawable/ic_launcher"/>
</item>
</layer-list>
Now the Issue is if I keep android:gravity="center" in bitmap, it makes my image too small for all devices.
If I keep this property in item it makes image ok for small phones but make it horrible for tabs.
I have tried everything, like using mimap (where I have all sizes of image) , using drawable where I have kept different sizes of nine patch image, but nothing seems to make the image look good.
(I have created ninepatch image using an online tool)
Now as keeping android:gravity="center" makes it just small (not blur), I want to know if I can increase this image size a bit more, using any work around?
I have wasted a lot of time to make it work, but nothing useful.
Thank you all in advance
This worked for me:
<item android:gravity="center">
<bitmap android:src="#drawable/ic_launcher"
android:gravity="center"/>
</item>
I want to give to a TextView a background. This background (classement_background.xml) is a drawable located in res/drawable.
Here's its code :
<?xml version="1.0" encoding="utf-8"?>
<shape
android:shape="ring"
xmlns:android="http://schemas.android.com/apk/res/android" >
<gradient
android:startColor="#ff648add"
android:endColor="#ff3656dd"
android:type="linear"
/>
</shape>
In the render window of the layout file, my background is set. (Android studio)
But for some reason, this drawable is not there anymore on a genymotion emulator nor an actual device.
I've been trying quite a few things (like making sure it isn't the first element in the drawable folder), but I can't figure out what's going on. Any thoughts ?
Here's the code from the textview itself : `
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E2"
android:id="#+id/classement"
android:layout_below="#+id/firstname"
android:layout_centerHorizontal="true"
android:textSize="85dp"
android:layout_marginTop="15dp"
android:padding="30dp"
android:background="#drawable/classement_background"
android:textColor="#android:color/white"/>`
Add the android:useLevel="false" attribute to your shape tag. My IDE didn't display your shape in its preview window until I added it.
According to the docs:
android:useLevel
Boolean. "true" if this is used as a LevelListDrawable. This should normally be "false" or your shape may not appear.
Try to set android:thickness for the shape. Maybe android doesn't provide a default thickness for the xml drawables.
Maybe I will post something, that helped me.
My backgroung id 1920x1920 pixels and display 1920x1080, so different size shouldn't be the problem.
I suppose that you have your background putted in some resource "drawable" folder (for example in drawable-hdpi) in Eclipse IDE. I had that either and on real device (Sony Xperia Z2) I haven't seen nothing.
Short answer:
I had to add my desired backgroung to every single drawable folder - drawable-ldpi, drawable-xxhdpi, ...
After this strange operation Sony finally recognized my backroung and accepted it. :-)
I hope this will help somebody.
In a start activity of our android application we're using a linearlayout with an background image for whole space.
The image size is 320x480 - the same as device resolution, we're using for testing.
The problem is, the image will be scaled und looks not so nice.
I tried to use imageview instead, but I've got black borders.
Some ideas, how to avoid scaling or how to get the proper size for background image?!
Thank you in advance.
Mur.
Create a background.xml file in res/drawable and use the following:
<?xml version="1.0" encoding="utf-8"?>
<bitmap
xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/background_image"
android:gravity="center"/>
And use this background.xml as your LinearLayout's background.
I'm using the following drawable:
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<gradient
android:startColor="#color/content_background_gradient_start"
android:endColor="#color/content_background_gradient_end"
android:angle="270"
/>
</shape>
The problem is that I get severe banding on hdpi devices (like the Nexus One and Droid) since the gradient goes from the top of the screen to the very bottom.
According to http://idunnolol.com/android/drawables.html#shape_gradient there isn't a "dither" attribute for a gradient. Is there anything I can do to smooth the gradient?
Note: adding dither="true" to shape doesn't seem to work.
I wrote the documentation you referenced. I've taken another look at the code and unfortunately there's no way to enable dithering on a GradientDrawable except by explicitly calling GradientDrawable.setDither() in code.
(The way the codes looks, technically you could include the Gradient as the only child of a <selector>, and enable dithering on the entire selector; however, it's definitely a hack.)
I'm not convinced enabling dithering will actually solve your problem, as dithering (at least as it's noted in the official Android docs) are for solving banding problems when the device has too small of a color palette. This seems to be a banding problem due to the size of the gradient.
Hi all i have the same problem, there is one solution which works but it's not very good.
getWindow().setFormat(PixelFormat.RGBA_8888);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);
It works for me but the problem is that the whole windows is dithered. I was looking to find a way to dither only the gradient but i couldn't find anything. android:dither="true" in xml is not working and GradientDrawable.setDither(true) is also not working. So any ideas how can i dither only the gradient ?
I faced a very similar problem last year and came to no useful conclusion on the android-developers list.
However, a while ago I discovered — after trying <gradient> and all sorts of Drawables with various dither attributes and manually creating dithered PNGs — that if I manually create a new image using GIMP, and specify the density at this point (i.e. explicitly entering 120, or 240 etc) when creating the image, it looks great, even on hdpi devices. And this is despite it being a grayscale gradient, with not so many colours.
The PNG when saved ends up being comparatively large (at least for 240dpi), but it looks great.