Issue
I want to create a View in Android with this background:
In the header should be two TextViews and a icon and the content can be different. My problem now is that I don't know the size of a TextView (or some other view) on the users device. So in which size should I store the picture so it is displayed correct on all devices? Of course I do not want to waste storrage for this picture in my app so I should be the smalest size.
Or is it posible to create something like this (particularly the shadow between header and content - which are only 2 lines of black and white with a transparency of 12%) in a shape?
Solution
You can use a 9patch image for this. Details can be found here but basically you'll only need a 2x1 pixel image. Then you can use the tool described in the link to generate a 9patch file which you use as your image file. Android then intelligently stretches the image for you depending on the width of the screen.
Alright, an edit:
I decided to help you a bit more. You're right about the NinePatch tool, it looks like it needs to be at least 2x4 large. I quickly made up a small image in Gimp
I then imported it into the NinePatch tool and set the appropriate not stretchable parts
Then I imported it into my drawable-nodpi folder and referenced it in an ImageView. Make sure you use android:scaleType="fitXY"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#FFC2C2C2" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:padding="5dp"
android:text="Header" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@drawable/gradient_line_image" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:padding="5dp"
android:text="Content" />
</LinearLayout>
which gives me
Just incase you want it, here's my 9patch file
I'm not sure at all what you mean by "both TextViews are in the header" though...
Answered By - roarster
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.