[code]_[限定符qualifier、smallest-width Qualifier]

同一份代码如下,在不同的模拟器上出现不同结果

res/layout/activity_main.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">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="this small layout"/>

</LinearLayout>
res/layout-large/activity_main.xml
<?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:layout_width="match_parent"
        android:layout_height="match_parent"
        android:text="this large's layout"/>

</LinearLayout>
入口mainactivity
package com.example.xiongchaochao.myapplication;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }
}

结果:


13671484-1ccafe933a5f195a.png
平板模拟器

13671484-e5e88d0d4cee5ff0.png
手机模拟器

刚才才说同一份代码,不同的结果,这里为什么会出现相同的结果呢?

  • 这里引入一个知识点:android 3.2版本之后,用smallest-width Qualifier最小宽度限定符取代了large,它定义最小宽度,如果设备屏幕宽度大于这个值,就视作大屏幕,使用大屏幕布局

根据上面的知识点,知道之所以出现这种情况,是因为这个large的最小宽度小于720px(模拟器分辨率为720p,版本为4.2)

所以要显示手机屏幕的布局,将layout-large文件夹更新为:layout-sw720dp,这里具体临界数值(大于临界值显示大屏布局,小于临界值显示小屏布局),需要计算,我这里只是一个泛值

res/layout-sw720dp/activity_main.xml
13671484-254895bfbffc70c4.png
手机模拟器
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值