[code]_[限定符qualifier、smallest-wi

2018-09-11  本文已影响0人  勤学奋进小郎君

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

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);
    }
}

结果:


平板模拟器
手机模拟器

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

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

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

res/layout-sw720dp/activity_main.xml

手机模拟器
上一篇 下一篇

猜你喜欢

热点阅读