您的位置:首页 > 移动开发 > Android开发

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

2015-04-29 00:00 330 查看
为不同分辨率的手机创建界面

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中布局文件。如果删除,则报错。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  布局 layout
相关文章推荐