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

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

结果:


[code]_[限定符qualifier、smallest-width Qualifier]
平板模拟器

[code]_[限定符qualifier、smallest-width Qualifier]
手机模拟器

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

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

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

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

res/layout-sw720dp/activity_main.xml

[code]_[限定符qualifier、smallest-width Qualifier]
手机模拟器

相关文章:

  • 2021-05-03
  • 2021-04-25
  • 2021-10-18
  • 2021-11-05
  • 2021-07-19
  • 2022-01-09
  • 2022-01-03
猜你喜欢
  • 2021-11-25
  • 2022-12-23
  • 2021-07-31
  • 2021-07-15
  • 2021-07-24
  • 2021-08-21
相关资源
相似解决方案