[英]Supporting Multiple Screens (phone and tablet)
我是android編程的初學者。 首先,我需要2種設備的手機(480x800)和平板電腦(1280x800)支持我的應用。
我讀了這篇,並試圖一步一步地做。 支持多屏
所以我用布局創建了文件夾:
res/layout/firstPage.xml//this is by default phone layout port and land
res/layout-sw720dp/firstPage.xml//this is tablet port layout
res/layout-sw720dp-land/firstPage.xml//this is tablet land layout
我的xml看起來像這樣:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_gravity="center_vertical"
android:baselineAligned="false"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:text="@string/button1" />
<Button
android:id="@+id/button2"
android:text="@string/button2" />
<Button
android:id="@+id/button3"
android:text="@string/button3" />
</LinearLayout>
我沒有提供有關按鈕的更多信息,因為在每種布局中它們都是不同的。
在我的AndroidManifest.xml中,有以下一行:
<supports-screens android:anyDensity="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:largeScreens="true"/>
如果我將tru設置為anyDensity =“ true”,也許我不需要為其他人設置true
所以我認為我盡了一切。 但是,當我想在平板電腦上測試時,默認情況下會顯示我的手機布局。 那我錯過了什么? 或者我還需要做一些編碼?
編輯:
我想我明白為什么...從Android 3.2(API級別13)開始,不建議使用上述大小組,而應使用swdp配置限定符定義布局資源所需的最小可用寬度。
我的桌子是3.1,所以為什么找不到布局? 但是,如果我想支持2.1到4,該怎么辦?
解決方法:
您應該遵循: 最佳實踐
嘗試對不同的屏幕尺寸使用不同的布局:
像:
res/layout/my_layout.xml // layout for normal screen size ("default")res/layout-small/my_layout.xml // layout for small screen size
res/layout-large/my_layout.xml // layout for large screen size
res/layout-xlarge/my_layout.xml // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation
根據設備的不同屏幕尺寸使用不同尺寸的圖像:
像:
res/drawable-mdpi/my_icon.png // bitmap for medium density
res/drawable-hdpi/my_icon.png // bitmap for high density
res/drawable-xhdpi/my_icon.png // bitmap for extra high density
仍然,如果不能解決您的問題,請為各個不同的布局使用圖像的靜態大小。
根據我的觀點和文檔,它自我說明您必須執行某些步驟。
希望對您有幫助。 如果沒有,請告訴我您在管理版式方面遇到的困難。
謝謝。
layout-sw720p僅適用於3.2及更高版本的android,不適用於3.0和3.1
希望這對您有所幫助,鏈接為http://developer.android.com/guide/practices/screens_support.html在“使用新的大小限定符->表2”下。屏幕大小的新配置限定符(在Android 3.2中引入)。
嘗試使用這個...
res/layout/firstPage.xml//this is by default phone layout port and land
res/layout-xlarge/firstPage.xml//this is tablet port layout
res/layout-xlarge-land/firstPage.xml//this is tablet land layout
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.