1.什么是屏幕适配
屏幕适配就是根据屏幕的大小,适配不同的尺寸。
通过对4种类型资源进行合理设计及规划,在布局时合理利用各种类型资源,让布局拥有适应能力,能在各种设备下保持良好的展现效果。
2.尺寸适配怎么做
1.创建不同分辨率的values文件夹,在其中分别创建dimens.xml:
2.在values-960x540目录下的dimens.xml里定义诸如下面这些尺寸:
3在Activity中的调用方法为:
![](https://i-blog.csdnimg.cn/blog_migrate/f7422d504af558ecec3a9fe8c4e3ee83.png)
3.图片适配怎么做
1.首先将相同的图片放入如图的文件夹中:
2.然后通过不同分辨率的手机,就能实现了。
4.什么是9.png图片
9.PNG是安卓开发里面的一种特殊的图片,这种格式的图片通过ADT自带的编辑工具生成,使用九宫格切分的方法,使图片支持在android 环境下的自适应展示。
在Android的UI设计开发中,很多控件需要适配不同的手机分辨率进行拉伸或者压缩,这样就出现了可以任意调整大小的一种图片格式“.9.png”。这种图片是用于Android开发的一种特殊的图片格式,它可以指定特定的区域进行拉伸而不失真,同时可以指定前景内容的显示区域。即.9.png图片的用处可以概括为以下两点:
- .9.png图片在图片拉伸的时候特定的区域不会发生图片失真;
- .9.png图片作为背景图的时候可以指定内容显示区域;
![](https://i-blog.csdnimg.cn/blog_migrate/2a07096c2609e4f0230418c1a3f3ac9d.png)
5.文字国际化(文字适配)怎么做
1.在src中创建一个values-en文件夹
2.新建一个strings-en文件
3.将里面的文字改成英文即可。
如图:
6.横竖屏适配怎么做
1创建一个layout-land文件夹,里面的布局文件要与layout的一样,如图:
layout的代码为:
1
2
3
4
5
6
7
8
9
|
<!--?xml version=
"1.0"
encoding=
"utf-8"
?-->
<linearlayout android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
android:orientation=
"vertical"
tools:context=
"com.example.androidthree.Main4Activity"
xmlns:android=
"https://schemas.android.com/apk/res/android"
xmlns:app=
"https://schemas.android.com/apk/res-auto"
xmlns:tools=
"https://schemas.android.com/tools"
>
<textview android:background=
"#666"
android:gravity=
"center"
android:layout_height=
"200dp"
android:layout_width=
"match_parent"
android:text=
"竖屏视频播放区"
android:textsize=
"30dp"
>
<linearlayout android:background=
"#999"
android:layout_height=
"50dp"
android:layout_width=
"match_parent"
>
<textview android:gravity=
"center"
android:layout_height=
"match_parent"
android:layout_weight=
"1"
android:layout_width=
"0dp"
android:text=
"简介"
>
<textview android:gravity=
"center"
android:layout_height=
"match_parent"
android:layout_weight=
"1"
android:layout_width=
"0dp"
android:text=
"评论"
>
</textview></textview></linearlayout>
</textview></linearlayout>
|
layout-land的代码为:
1
2
3
4
|
<!--?xml version=
"1.0"
encoding=
"utf-8"
?-->
<linearlayout android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
android:orientation=
"vertical"
tools:context=
"com.example.androidthree.Main4Activity"
xmlns:android=
"https://schemas.android.com/apk/res/android"
xmlns:app=
"https://schemas.android.com/apk/res-auto"
xmlns:tools=
"https://schemas.android.com/tools"
>
<textview android:background=
"#666"
android:gravity=
"center"
android:layout_height=
"match_parent"
android:layout_width=
"match_parent"
android:text=
"竖屏视频播放区"
android:textsize=
"30dp"
>
</textview></linearlayout>
|