屏幕适配

屏幕适配:即:尺寸单位,图片,文字,布局,这四种进行合理调配
如何尺寸单位适配:
首先在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>
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值