網站首頁 編程語言 正文
使用限定符
在平板上面大多數時候采用的雙頁的模式,程序會在左側列表上顯示一個包含子項列表,右側的面版會顯示詳細的內容的因為平板具有足夠大的屏幕.完全能夠顯示兩頁的內容.但是在手機上手機只能顯示一頁的內容,因此需要兩個頁面分開顯示.
- 在運行時判斷程序應該使用雙頁模式還是單頁模式,需要借助限定符==(qualifier)==來進行實現.
- 在layout/activity_main.xml中只包含一個Fragment,即單頁模式
<?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" android:orientation="horizontal"> <fragment android:id="@+id/leftFrag" android:name="com.zb.fragmenttest.LeftFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_weight="1" /> </LinearLayout>
創建一個layout_large目錄,在這個目錄下創建一個同樣名為activity_main.xml的文件,但是在該布局當中包含兩個Fragment,即雙頁模式.
<?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" android:orientation="horizontal"> <fragment android:id="@+id/leftFrag" android:name="com.zb.fragmenttest.LeftFragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /> <fragment android:id="@+id/rightFrag" android:name="com.zb.fragmenttest.RightFragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" /> </LinearLayout>
- 解決在Android開發中layout_large目錄下不能創建xml文件的方法:https://blog.csdn.net/CEVERY/article/details/86593814
- 其中large就是一個限定符,那些屏幕被認為是large的設備就睡加載layout_large文件夾下的布局,小屏幕設備則還是會加載layout文件夾下面的布局.
- 這樣就可以實現動態加載布局的功能.
- 安卓中常見的限定符
使用最小寬度限定符
- 最小寬度限定符,允許我們對屏幕的寬度指定一個最小值(以dp為單位)
- 然后以這個最小值為臨界點.屏幕寬度大于這個值得設備就加載一個布局
- 屏幕寬度小于這個值得就加載另外一個布局
- 在res目錄下新家一個layout-sw600dp文件夾,然后在這個文件夾下面建一個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" android:orientation="horizontal"> <fragment android:id="@+id/leftFrag" android:name="com.zb.fragmenttest.LeftFragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" /> <fragment android:name="com.zb.fragmenttest.RightFragment" android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="3" /> </LinearLayout>
這就意味著,當程序運行在屏幕寬度大于等于600dp的設備上時,會加載layout_sw600dp/activity_main布局,當程序運行在屏幕寬度小于600dp的設備上的時候,則仍然加載默認的layout/activity_main布局.
原文鏈接:https://blog.csdn.net/weixin_45809829/article/details/128064733
相關推薦
- 2022-06-29 徹底掌握C語言strcat函數的用法_C 語言
- 2022-06-02 C語言實現簡單的抽獎系統_C 語言
- 2022-04-19 盤點分析C語言中少見卻強大的字符串函數_C 語言
- 2022-06-01 Python+Opencv實現計算閉合區域面積_python
- 2022-07-16 windows下的SDL開發環境搭建(基于mingw編譯運行)
- 2023-02-14 Android?SharedPreference存儲文件三步走_Android
- 2022-05-27 go語言實現兩個協程交替打印_Golang
- 2022-02-20 千分位保留兩位小數,出現“toFixed() is not a function”的解決辦法
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支