当前位置:操作系统 > 安卓/Android >>

android程序界面自动适应屏幕分辨率例子

 

为不同分辨率的手机创建界面

1,首先进入res 文件夹下。

2,创建一个名为“layout-1024x768”文件夹,

其中1024x768 是屏幕分辨率的大小,值得注意的是分辨率中大的数字必须写到前面,否

则会产生语法错误。如layout-768x1024 的写法是错误的。

3,编写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:id="@+id/tv"

android:layout_height="wrap_content" android:text="1024x768" />

</LinearLayout>

4,在按照上述创建layout-1280x800分辨率的文件夹,main.xml直接拷贝。

5,分别创建1024x768和1280x800的模拟器:

6,注意在AndroidManifest.xml中添加     <supports-screens android:largeScreens="true"

android:anyDensity="true" />否则,你的应用不会全屏。

详细见例子helloword。

7,最后,默认layout,不要删掉,如果指定分辨率不存在的时候,会默认调用layout中布局文件。如果删除,则报错。  

补充:移动开发 , Android ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,