定义基于屏幕密度layout.xml文件(v.2.3.3 +) [英] Defining layout.xml files based on screen density (v.2.3.3+)

查看:242
本文介绍了定义基于屏幕密度layout.xml文件(v.2.3.3 +)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知分辨率关心的是密度(纠正我,如果我错了),我的目标是使用根据设备的密度三种布局之一。我算什么用2.3.3(最流行的大气压)的SDK版本选择?
谢谢你。

Afaik resolution is concerned with density (correct me if I'm wrong) and my goal is to use one of three layouts according to device's density. What're my options with 2.3.3 (most popular atm) sdk version ? Thank you.

推荐答案

看看关于支持多屏幕的Andr​​oid文档 - 的要点是,你可以有针对基础设备不同的命名惯例多个文件夹
 对事物的整体阵列(屏幕像素密度,屏幕尺寸,纵向/横向等),它们可以像模糊或尽可能详细,你想要的。
例如,如果你想针对你做出所谓的布局xhdpi布局文件夹中所有xhdpi设备,使布局里面,所有的设备xhdpi将使用于其他任何。如果你想更具体,例如针对Galaxy Nexus的具体情况,你可以创建一个名为布局w360dp端口-xhdpi文件夹。

Take a look at the android documentation about supporting multiple screens - the gist is that you can have multiple folders with different naming conventions that target devices based on a whole array of things (screen density, screen size, portrait/landscape etc) and they can be as vague or as detailed as you want. For example if you wanted to target all xhdpi devices you make a layout folder called 'layout-xhdpi', make a layout inside it and all xhdpi devices will use that over any other. If you wanted to be more specific and for example target the Galaxy Nexus specifically you can create a folder named 'layout-w360dp-port-xhdpi'.

我preFER做的另一种方法是有一个单一的布局文件和有多个价值的XML文件针对不同的屏幕尺寸,并且在值的文件变更为填充/高度和指向拍摄中的值这些值在布局。例如在价值/ dimensions.xml

Another way which I prefer to do is have a single layout file and have multiple 'values' xml files targeting the different screen sizes, and in the values files change the values taken in for padding/heights and point to these values in your layout. e.g. in 'values/dimensions.xml'

<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="webview_height">53dip</dimen>
<resources>

然后在您的布局:

then in your layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical" >
<WebView 
    android:layout_height="@dimen/webview_height"
    android:id="@+id/mainWebViewMobile"
    android:layout_width="match_parent"
    ></WebView>
</LinearLayout>

和您可以创建单独的文件夹,针对不同的设备(例如'价值观xhdpi / dimensions.xml或价值观w360dp端口-xhdpi / dimensions.xml')多dimensions.xml和改变的webview_height价值

and you can create multiple dimensions.xml in separate folders targeting different devices (e.g. 'values-xhdpi/dimensions.xml' or 'values-w360dp-port-xhdpi/dimensions.xml') and alter the value of 'webview_height'.

这篇关于定义基于屏幕密度layout.xml文件(v.2.3.3 +)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆