当前位置: 代码迷 >> Android >> Android分辨率自适应有关问题的解决
  详细解决方案

Android分辨率自适应有关问题的解决

热度:75   发布时间:2016-05-01 15:14:09.0
Android分辨率自适应问题的解决
Android 中的显示单位
Android 中的显示单位应该有所了解,作如下简介:
? px (pixels)像素
一般 HVGA 代表 320x480 像素,这个用的比较多。
? dip 或 dp (device independent pixels)设备独立像素
这个和设备硬件有关,一般为了支持 WVGA、HVGA 和 QVGA 推荐使用这个,不依赖像素。
? sp (scaled pixels — best for text size)比例像素
主要处理字体的大小,可以根据系统的字体自适应。
下面几个不太常用:
? in (inches)英寸
? mm (millimeters)毫米
? pt (points)点,1/72 英寸
为了适应不同分辨率,不同的像素密度,推荐使用 dip,文字使用 sp。

不同分辨率的手机创建界面
仍然在 HelloWorld 项目中进行改进。
首先进入 res 文件夹下

创建一个名为“layout-320x240”文件夹,
其中 320x240 是屏幕分辨率的大小,值得注意的是分辨率中大的数字必须写到前面,

则会产生语法错误。如 layout-240x320 的写法是错误的。

编写 main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="320x240"
/>
</LinearLayout>

再创建一个文件夹“layout-480x320”

编写 main.xml 文件
<?xml version= "1.0" encoding= "utf-8"?>
<LinearLayout
xmlns:android= "http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height= "fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height= "wrap_content"
android:text="@string/hello"
/>
<TextView
android:layout_width="fill_parent"

android:layout_height= "wrap_content"
android:text="480x320"
/>
</LinearLayout>
  相关解决方案