xiao
xiao

Reputation: 651

How to figure out how what sizes images should be for multiple screens?

I am still kinda confused on how to re size images to fit on a small,normal and large screen on an android phone.

Say I have a image that is 500px by 500px and is a JPG.

I want to make 4 image buttons making it a 2 by 2 in the center of the screen. For simplicity sake assume I am using this same image for all 4 buttons.

Now how do I figure out how much I need to re size the image down for each of the screens?

So that it would look like this in the center of the view.

x   x

x   x

Upvotes: 1

Views: 134

Answers (2)

Jeremy Edwards
Jeremy Edwards

Reputation: 14760

I think you want a 9-patch drawable (*.9.png). They allow you to make stretchable graphics and declare a content fill region. Android's stock buttons use them.

http://developer.android.com/guide/developing/tools/draw9patch.html

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

For buttons you'll probably want to make them change based on what state they are in. You use StateList drawables for that.

http://developer.android.com/guide/topics/resources/drawable-resource.html#StateList

Here's an example of a button StateList from one of my apps to render an Action Bar button.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" android:drawable="@color/slight_white" /> <!-- pressed -->
    <item android:state_focused="true" android:drawable="@android:color/transparent" /> <!-- focused -->
    <item android:drawable="@android:color/transparent" /> <!--menu_normal default -->
</selector>

In this case I'm using colors but you can of course replace that with any drawable as well. Including the 9-patches drawables you make.

For a full fledged example look at the source code that comes with the SDK.

%ANDROID_SDK_ROOT%\platforms\android-12\data\res\drawable\btn_default.xml

Upvotes: 1

Squonk
Squonk

Reputation: 48871

Have you looked at Supporting Multiple Screens in the Android Dev Guide?

Upvotes: 1

Related Questions