Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I know there are plenty of materials about my question. But I'm still confused how to design android app to support difference sizes of screen.

Mostly when I design web, I use percent to support different size of screens. But as you know, in android, in order to do that, I have to make UI in realtime using Java code(read width and height and resize all the Views depending on screen size), because with XML, you can't do this. But this seems not right.

I have image files(PNG, JPG), and I arrange these files as ImageView and scaleType as "fitXY" and I set width as DP. I know that "dp" unit will make this element consistently same real size and for this reason people use it for widgets. So I put this image in xxxhdpi screen and when I see in xhdpi screen, image is so huge that the image is cut.

What I want is very simple. I want to arrange View elements as percent to width so that layout is very similar in different screens(different height ratio will be resolved with scroll maybe?). But I don't know how to...???? Not only percent.. I just want to know normal process of generating image files and arranging widgets for different screens...

Should I make many image files for different screen and put these in res/drawable-xxxxx ? If I do this, does android system use different files for different screen automatically? Or, Should I make many layouts for each different screen all the time(this seems stupid..)?

Could anyone guide me please?... I have been looking for this answer more than 1 week. Please...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
185 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can create different layout folders and create layouts for standard screen sizes. There is a set of six generalized densities:

ldpi (low) ~120dpi
mdpi (medium) ~160dpi
hdpi (high) ~240dpi
xhdpi (extra-high) ~320dpi
xxhdpi (extra-extra-high) ~480dpi
xxxhdpi (extra-extra-extra-high) ~640dpi

You can create images and layouts for these and use accordingly.Mention that in you manifest also:

<compatible-screens>
    <screen
        android:screenDensity="ldpi"
        android:screenSize="small" />
    <screen
        android:screenDensity="mdpi"
        android:screenSize="normal" />
    <screen
        android:screenDensity="xhdpi"
        android:screenSize="large" />
    <screen
        android:screenDensity="xhdpi"
        android:screenSize="xlarge" />        
</compatible-screens> 

Refer Supporting Multiple Screens for more details.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...