开发者

Getting my android apps to scale to larger screen

开发者 https://www.devze.com 2023-03-27 17:18 出处:网络
I\'ve tried over and over again to get my app to sc开发者_如何学JAVAale to larger screens (like my new sensation, and my galaxy tab).

I've tried over and over again to get my app to sc开发者_如何学JAVAale to larger screens (like my new sensation, and my galaxy tab).

No matter what I do to my .xml layout files, the app shows up like it's on a small screen (black open space around the app).

Is there anyway to just make my app stretch to fit the screen without rewriting all my layouts, or providing new images? I realize I may get some blur, but I'm ok with that for now.

Thanks!


make sure to include this in your android manifest xml:

<uses-sdk 
    android:targetSdkVersion=x 
    android:minSdkVersion=y>
</uses-sdk>

where x is the target sdk version and y is the minSdkVersion.


There are several ways.

That what you need is the Android Screen Compatibility Mode. In your case you have to add the following in your Manifest file:

<supports-screens android:xlargeScreens="true" />

This declares that your application supports all larger screen sizes.That has the effect that the system will always resize your layout to fit the screen.

In general is it important that you do not use an Absolute-Layout. You should use for different screen resolutions, different folders for graphics and if necessary different .xml layout files.

That could like as follows:

res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size

res/drawable-mdpi/my_icon.png        // bitmap for medium density
res/drawable-hdpi/my_icon.png        // bitmap for high density
res/drawable-xhdpi/my_icon.png       // bitmap for extra high density

You should use wrap_content, fill_parent, or dp units when specifying dimensions in an XML layout file.


You have to put

<uses-sdk android:minSdkVersion="4"/> 

to your manifest file. Version of api earlier 1.5 doesn`t supports streching of the screen and on the big-size screens it will remains small with black space around.


I created a tool that allows you to scale/adjust your layouts for tablets and small screen devices and made a blog post about it here: http://onemanmobile.blogspot.com/2012/04/how-to-scale-your-android-layouts-to.html

Basically, defining your layouts in dp units is not enough if you want your app to fit on all devices and tablets, since there's four different "density-buckets". This tool will allow your layouts to be converted into fitting these density buckets.

I hope the blog, tool and answer will help others, I know it felt good to have my app work on a tablet with the press of a button.


<manifest xmlns:android="http://schemas.android.com/apk/res/android">
...
    <uses-sdk android:minSdkVersion="10" android:targetSdkVersion="10" />
...
</manifest>

It solved my problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消