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>
Related
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 my eclipse, when ever I have a scrollView and a background image set up at the same time, my background image stretches vertically. I would like it not to stretch but repeat all the way down the ScrollView.
Please help
Create a XML file within the drawable:
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="#drawable/my_image"
android:tileMode="repeat" />
than you can use this file as your drawable, and it will be repeated
Note that there is a bug related to repeat (android 3.0 and bellow), when used in a listview
see XML drawable Bitmap tileMode bug?
I want to create some kind of row image that looks like that
but I want it to scale with the screen size and density. So reading this http://developer.android.com/guide/developing/tools/draw9patch.html and this http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch I startet creating a Nine-patch image.
But when I import it and use it in my android project it looks like that
As you can see the little black line that was drawn with the draw 9 patch tool is still visible. Why?
Here is the 9.png image
Are you using the draw9patch tool that comes with the sdk? it is quite handy.
Anyway:
It is vital that every pixel except the black ones are completely
transparent.
The black pixels should be at the absolute top/bottom/left/right of
the image.
The image should be named filename.9.png.
I have found the best and the simplest answer to make 9-patch image.
This is best link to create 9-patch image for all the resolutions - XHDPI, HDPI, MDPI, LDPI in just one click.
Let me know if you have any queries, and do upvote it, if it was helpful to you.
If you need an image which consists of a border with rounded corners, I don't have to create a 9-patch.
All you need is an XML like this stored in the res/drawable directory
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<corners android:radius="3.0dp" />
<stroke
android:width="2dp"
android:color="#color/green" />
</shape>
Read more about drawable resources
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.
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