使用不同的屏幕布局

时间:2016-09-12 20:26:51

标签: android android-layout

我有一个不同版本的应用程序,用于屏幕(小型,普通,largue和extraLargue XML文件),每个版本都有针对每种类型设计的XML,但我发现华为手机的屏幕为3.5“HVGA 320x480。

我的问题是,Android的UI是否应该使用此屏幕的小配置?这个应用程序在这款手机上运行时使用正常配置,好像它是一个nexus4 4.7“768x1280,因为我改变了吗?

我尝试使用多种配置创建各种类型的屏幕(创建其他)而没有最佳效果。

2 个答案:

答案 0 :(得分:1)

假设3.5英寸的测量位于对角线上,根据Android的支持多屏指南,这可以达到大约165 dpi,落入mdpi(或普通屏幕尺寸)存储桶。

DPI = sqrt(w^2 + h^2) / d

where 

w is the width of the display in pixels
h is the height of the display in pixels
d is the physical diagonal measurement of the display in inches

答案 1 :(得分:-1)

很简单。
您需要添加不同的用户界面并制作控件VISIBILEGONE

int appScreen = getResources().getConfiguration().screenLayout &
        Configuration.SCREENLAYOUT_SIZE_MASK;


switch(appScreen) {
    case Configuration.SCREENLAYOUT_SIZE_LARGE:
    UIControl.setVisibility(View.GONE);
        break;
    case Configuration.SCREENLAYOUT_SIZE_NORMAL:
    UIControl.setVisibility(View.GONE);
        break;
    case Configuration.SCREENLAYOUT_SIZE_SMALL:
    UIControl.setVisibility(View.GONE);
        break;
    default:
    UIControl.setVisibility(View.GONE);
}
相关问题