2011-06-13 167 views
0

從前幾天我試圖創建一個應用程序,可以根據模擬器的大小更改調整屏幕..我發現使用多個屏幕的解決方案。Android上的多屏幕支持

但我無法做到這一點 我已經從this接受了幫助,但無法理解我怎麼能setContentView(R.layout.main);?因爲當我R後,按。(點)不告訴我這個文件夾下面.. :( 我創建了res文件夾下的layout-largelayout-smalllayout-large-land 3個文件夾在我的Android應用程序

我已經添加到這一點我的清單文件..

<supports-screens 
      android:largeScreens="true" 
      android:normalScreens="true" 
      android:smallScreens="true"  
      android:anyDensity="true" /> 

enter image description here

我是缺少在這裏什麼事?我在提前採用了android 1.6的感謝 的問題是我是否已經提供這main.xml文件默認layout folder也?是的話那麼在屏幕尺寸CHAGE沒有影響沒有那麼它關閉我的應用程序強制我已經使用API level 7也不過問題試圖保持相同 這是我的xml文件

<?xml version="1.0" encoding="utf-8"?> 



<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:id="@+id/rl" 
    android:layout_height="360dip"> 
    <!-- 
     <WebView android:id="@+id/webviewHelp" 
     android:layout_width="fill_parent" 
    --> 
    <!--  android:layout_height="fill_parent" />--> 
    <WebView android:id="@+id/webviewHelp" android:layout_width="fill_parent" 
     android:layout_height="fill_parent" /> 
    <Button android:id="@+id/My_btn" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" android:gravity="center" 
     android:textSize="8px" android:text="Download this mp3 file" 
     android:textColor="@color/white" android:layout_width="fill_parent" 
     android:layout_height="28dip" android:visibility="invisible" /> 
    <Button android:id="@+id/My_btn1" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" android:text="this is button !" 
     android:layout_width="0dip" android:layout_height="0dip" 
     android:visibility="invisible" /> 


</RelativeLayout> 
+2

的setContentView(R.layout.main)將是相同的。根據模擬器的大小,android會假定要考慮哪個文件夾。 – Lavanya 2011-06-13 05:31:14

+0

它不會顯示任何文件夾名稱,但默認佈局,它不是你的頭痛,Android會自動選擇合適的文件夾 – ingsaurabh 2011-06-13 05:31:52

+0

查看我更新的代碼 – Android 2011-06-13 06:11:34

回答

0

請您之前在這些文件夾中添加一些佈局個XML在R之後鍵入點號:) 這些文件夾本身不會生成資源ID,但其中的xml文件卻可以。

+0

但這個文件必須在m佈局文件夾中嗎?其他應用程序強制關閉,如果我提供,然後它採取它並顯示在屏幕視圖更改沒有更改我更新的代碼 – Android 2011-06-13 06:05:17

+0

查看我的更新的代碼 – Android 2011-06-13 06:16:08

+0

您將不同的佈局文件放在不同的文件夾,Android運行時選擇文件夾中的一個其名稱與當前設備屏幕顯示度量和方向相匹配。 例如:'setContentView(R.layout.main);'如果設備有* large *屏幕並且當前處於* portrait *方向或文件夾中,''會將main.xml加載到'layout-large-port'文件夾中如果當前具有*小*屏幕並且處於*橫向*方向,則佈局小陸地。如果Android在所需文件夾中找不到名爲main.xml的文件,則在這兩種情況下都會引發異常。 – 2011-06-13 09:35:31