屏幕适配:根据手机尺寸,可以适应自适应大小。
即:尺寸单位,图片,文字,布局,这四种进行合理调配
如何尺寸单位适配:
首先在AndroidAtudio中将调整为project
然后在app–>main–>res新建两个ddirectory分别命名为values-960x540和1184x720
在新建的两个文件夹下分别创建dimens.xml 注意dimen name=”app-width”两个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">400dp</dimen>
</resources>
然后在activity的布局文件中调用这两个布局
2.图片适配
3.9.png
四个点可以无限延伸
4.文字国际化
在app–>main–>res新建一个ddirectory分别命名为values-en,把values中的Strings.xml文件复制一份在values-en中,同时添加
注意所要用到的标签要一样
strings.xml:
<resources>
<string name="app_name">My NewApplication</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="test">今天</string>
</resources>
values_en:
<resources>
<string name="app_name">My NewApplication</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="test">TODAY</string>
</resources>
然后在activity布局文件中要引用这个布局:
<TextView
android:text="@string/test"
android:layout_width="match_parent"
android:layout_height="80dp" />
5.横竖屏屏幕适配
app–>main–>res新建一个ddirectory命名为layout_land然后新建一个layout resource file文件
注意文件名一定要和所需要加载的activity布局文件的名字相同
layout_land:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:textSize="25sp"
android:gravity="center"
android:text="视频正在播放....."
android:background="@mipmap/button_ts"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
activity中的布局文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_vido"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.xiaozhen.mynewapplication.VidoActivity">
<TextView
android:textSize="25sp"
android:gravity="center"
android:text="视频正在播放....."
android:background="@mipmap/button_ts"
android:layout_width="match_parent"
android:layout_height="200dp" />
<TextView
android:text="广告。。。。。"
android:layout_width="match_parent"
android:layout_height="40dp" />
<ImageView
android:src="@mipmap/ic_launcher"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:text="@string/test"
android:layout_width="match_parent"
android:layout_height="80dp" />
</LinearLayout>