开发者

screen adjusting ability feature in android

I have an application which is designed for a fixed screen size.But when i install the application on a device with different screen size ,i am not able to view the complete application. Is it possible to allow layout adjustments based on variable screen sizes? ... like setting width with some % of screen size which is decided when application installation is done For eg: 60% of screen size or 60% of relat开发者_如何学运维ive layout


Yes, this is actually very easy in Android: just dont declare a screen size, and let the OS handle it. The only time your screen is a fixed size is when you declare it as a fixed size. If you're having trouble, go back to the first tutorials from google. In their layouts, they never explicitly declare a screen size.

Hope this was helpful.


You can find out about the size of the screen by using getWindowManager().

So, for example, to find out what 60% of your screen width is you could do this in your onCreate() method:

DisplayMetrics dm = new DisplayMetrics(); 
getWindowManager().getDefaultDisplay().getMetrics(dm); 
int sixtyPercentScreenWidth = (int) Math.round(dm.widthPixels * 0.6);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜