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中布局文件。如果删除,则报错。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值