实训—屏幕适配

什么是屏幕适配?

Android中屏幕适配就是通过对尺寸单位、图片、文字、布局这四种类型的资源进行合理的设计和规划,在布局时合理利用各种类型的资源,让布局拥有适应能力,能在各种设备下保持良好的展现效果。

尺寸适配怎么做?

屏幕尺寸指屏幕的对角线的长度,mdpi、hdpi、xdpi、xxdpi、代表不同的密度设备。
1.分别创建mdpi、hdpi、xdpi、xxdpi的模拟器
2.观察尺寸、分辨率、dpi分别是多少。
3.在res下新建valus-960*540、valus-1184*720文件夹,分别创建名为dimens.xml的文件
4.为每个dimens.xml创建一个标签,name为app_width,值分别为100dp和800dp。
5.在acyivity_main.xml中创建一个Button。

6.分别观察Button的变化。

图片适配怎么做?

根据不同密度的手机,可以分别设计不同尺寸的图片放入对应的drawable的文件夹中,Android系统会根据当前运行的设备密度,加载对应文件夹中的图片。

什么是.9.png图片

.9.PNG是安卓开发里面的一种特殊的图片,这种格式的图片通过ADT自带的编辑工具生成,使用九宫格切分的方法,使图片支持在android 环境下的自适应展示。

文字国际化(文字适配)怎么做?

1.当手机语言为英文时,App中的文字显示英文:在res下新建values-en文件夹,并在此创建string.xml。字符串内容为英文格式。
2..当手机语言为英文时,App中的文字显示中文:在res下新建values文件夹,并在此创建string.xml。字符串内容为中文格式。
3.在2个string.xml中分别定义key为app_name,value分别为WeChat和为微信的字符串,调整手机语言,观察字符串是否切换。
4.每个文件夹中string.xml文件的命名一致。

横竖屏适配怎么做?

res/layout/main.xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="fill_parent"  
    android:layout_height="fill_parent"  
    android:orientation="vertical" >  

    <include  
        android:id="@+id/layout_test"  
        layout="@layout/layout" />  

</LinearLayout>  
res/layout-land/layout.xml:
[html] view plain copy
<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:orientation="vertical" >  

    <TextView  
        android:id="@+id/textView1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_gravity="center"  
        android:text="横屏布局" />  

</LinearLayout> 
res/layout-port/layout.xml:
<?xml version="1.0" encoding="utf-8"?>  
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
    android:layout_width="match_parent"  
    android:layout_height="match_parent"  
    android:orientation="vertical" >  

    <TextView  
        android:id="@+id/textView1"  
        android:layout_width="wrap_content"  
        android:layout_height="wrap_content"  
        android:layout_gravity="center"  
        android:text="竖屏布局" />  

</LinearLayout> 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值