屏幕适配

一.什么是屏幕适配

屏幕适配就是根据屏幕的大小,适配不同的尺寸。

二.尺寸适配怎么做

1.创建不同分辨率的values文件夹,在其中分别创建dimens.xml:

这里写图片描述

2.在values-960x540目录下的dimens.xml里定义诸如下面这些尺寸:

这里写图片描述

3在Activity中的调用方法为:

这里写图片描述

三.图片适配怎么做

1.首先将相同的图片放入不同尺寸的dpi文件夹中:

这里写图片描述

2.然后通过不同分辨率的手机,就能实现了。

四.什么是9.png图片

9png图片一般用在需要拉伸的地方,比如聊天程序的对话框,字数不同,对话框的大小也不同。效果如图:

这里写图片描述

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

1.在res中创建一个values-en文件夹

2.新建一个strings-en文件

3.将里面的文字改成英文即可。

如图:

这里写图片描述

六.横竖屏适配怎么做

1创建一个layout-land文件夹,里面的布局文件要与layout的一样,如图:

这里写图片描述

layout的代码为:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.androidthree.Main4Activity">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:text="竖屏视频播放区"
        android:textSize="30dp"
        android:gravity="center"
        android:background="#666"
        />
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="#999"
        >
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="简介"
            android:gravity="center"/>

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="评论"
            android:gravity="center"/>
    </LinearLayout>
</LinearLayout>

layout-land的代码为:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.example.androidthree.Main4Activity">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="竖屏视频播放区"
        android:textSize="30dp"
        android:gravity="center"
        android:background="#666"
        />

</LinearLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值