屏幕适配
1.什么是屏幕适配
Android中屏幕适配就是通过对尺寸单位、图片、文字、布局这四种类型的资源进行合理的设计和规划,在布局时合理利用各种类型的资源,让布局拥有适应能力,能在各种设备下保持良好的展现效果
2.尺寸适配怎么做
使得布局元素自适应屏幕尺寸
根据屏幕的配置来加载相应的UI布局
3.图片适配怎么做
根据不同密度的手机,可以分别设计不同尺寸的图片放入对应的drawable的文件夹中,Android系统会根据当前运行的设备密度,加载对应文件夹中的图片。
1.在布局文件中创建一个ImageView,src属于性指向animal.png。
2.分别在hdpi、mdp、xdp的设备上运行,观察加载哪个文件夹中的图片。
3.在进行开发的时候,我们需要把合适大小的图片放在合适的文件夹里面
4.什么是9.png图片
9.PNG,这是安卓开发里面的一种特殊的图片
这种格式的图片在android 环境下具有自适应调节大小的能力。
(1)允许开发人员定义可扩展区域,当需要延伸图片以填充比图片本身更大区域时,可扩展区的内容被延展。
(2)允许开发人员定义内容显示区,用于显示文字或其他内容
5.文字适配怎么做
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文件的命名一致。
6.横竖屏适配怎么做
<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>
<?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>
<?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>