1.什么是屏幕适配
屏幕适配就是通过对尺寸单位、图片、文字、布局这四种类型的资源进行合理的设计和规划,在布局时合理利用各种类型的资源,让布局拥有适应能力,能在各种设备下保持良好的展现效果。
2.尺寸适配怎么做
1.在res下新建values-960x540,values-1184x720文件夹,分别创建名为dimens.xml的文件。
values-960x540:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="app_width">100dp</dimen>
</resources>
values-1184x720:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="app_width">800dp</dimen>
</resources>
2.为每个dimens.xml创建一个dimen标签, name为app_width, 值分别为100dp和800dp。
3.在activity_main.xml中创建一个Butto, 设置其宽度时,使用android:layout=”@dimen/app_width”。
4.分别在正常分辨率,960*540分辨率,1184*720分辨率下运行,观察Butto的宽度变化。
3.图片适配怎么做
4.什么是9.png图片
9.PNG是安卓开发里面的一种特殊的图片,这种格式的图片通过ADT自带的编辑工具生成,使用九宫格切分的方法,使图片支持在android 环境下的自适应展示。
5.文字国际化(文字适配)怎么做
先创建文件夹
国际化时,英语环境下的,文件夹命名为: values-en
国际化时,中文环境下的,文件夹命名为: values-zh
在res文件夹下创建values-zh-rCN文件夹 然后创建stirng.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Demo_0103_文字国际化</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="taobao">淘宝!</string>
<string name="sex">性别!</string>
</resources>
在res文件夹下创建values-en-rUS或values-en-rGB或values-en-rCA文件夹, 然后创建stirng.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Demo_0103_文字国际化</string>
<string name="action_settings">Settings</string>
<string name="hello_world">Hello world!</string>
<string name="taobao">Tao Bao!</string>
<string name="sex">Sex!</string>
</resources>
6.横竖屏适配怎么做
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:
<?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>