2011-03-01 130 views
2

我最近開發了一個使用Eclipse的android遊戲。我真的是一個新手,所以原諒我,如果我會問的太簡單了。 >。 <ANDROID佈局從模擬器變成了平板電腦

應用程序在安裝在Eclipse中的Android模擬器中運行並看起來很完美。但是,當我們試圖將它安裝在明顯比模擬器更大屏幕的Samsung Galaxy標籤中時,佈局會變得混亂。按鈕沒有按照正確的順序排列等。我確實使用XML佈局進行了屏幕顯示,有些是帶有精靈的簡單畫布。任何想法如何保留模擬器中的原始佈局到平板電腦?我試過使用RelativeLayout而不是LinearLayout,但它仍然不起作用。

任何幫助,將不勝感激。謝謝!

一個XML文件代碼,它來自下面顯示的仿真器的相應屏幕。

<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
style="@style/MenuLayout" > 

<Button android:id="@+id/btnNew" 
    android:layout_width="140px" 
    android:layout_height="65px" 
    android:layout_marginTop="160px" 
    android:background="@drawable/newgame"/> 
<Button android:id="@+id/btnInst" 
    android:layout_width="140px" 
    android:layout_height="65px" 
    android:background="@drawable/instructions" /> 
<Button android:id="@+id/btnCredits" 
    android:layout_width="140px" 
    android:layout_height="65px" 
    android:background="@drawable/credits"/> 
<Button android:id="@+id/btnExit" 
    android:layout_width="140px" 
    android:layout_height="65px" 
    android:background="@drawable/exit"/> </LinearLayout> 

corresponding image for xml above

+3

它肯定會幫助你發佈一些關於這個佈局問題的圖片。和佈局文件。 – 2011-03-01 15:48:52

+0

當你想在任何尺寸的屏幕上顯示正確的東西時,應該使用RelativeLayout。設置尺寸時,您還應該確保使用傾角而不是像素。 – 2011-03-01 16:00:19

+0

建議:你也可以設置一個三星Galaxy Tab模擬器,在這裏看到詳細信息:[http://innovator.samsungmobile.com/galaxyTab.do]我相信你的問題出現,因爲你沒有正確編程爲不同的屏幕尺寸和密度(如使用px),而不是模擬器/設備本身。 – Adinia 2011-03-01 16:02:50

回答

0

正如其他人所說,你應該使用「DP」,而不是「像素」。這些是與設備無關的像素,可以縮放以匹配不同的屏幕分辨率。

您還應該按照此guide關於如何使用文件夾結構來支持不同的屏幕分辨率和尺寸。

乾杯

0

根據您編輯的問題,上的評論,在這裏是一種方法,你的佈局改變到一個相對:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    style="@style/MenuLayout" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <Button android:id="@+id/btnNew" 
     android:layout_width="140dip" 
     android:layout_height="65dip" 
     android:layout_marginTop="160dip" 
     android:background="@drawable/newgame" 
     android:layout_centerHorizontal="true" 
     android:layout_above="@+id/btnInst" /> 

    <Button android:id="@+id/btnInst" 
     android:layout_width="140dip" 
     android:layout_height="65dip" 
     android:background="@drawable/instructions" 
     android:layout_centerHorizontal="true" 
     android:layout_above="@+id/btnCredits"/> 

    <Button android:id="@+id/btnCredits" 
     android:layout_width="140dip" 
     android:layout_height="65dip" 
     android:background="@drawable/credits" 
     android:layout_centerHorizontal="true" 
     android:layout_above="@+id/btnExit"/> 

    <Button android:id="@+id/btnExit" 
     android:layout_width="140dip" 
     android:layout_height="65dip" 
     android:background="@drawable/exit" 
     android:layout_centerHorizontal="true" 
     android:layout_alignParentBottom="true" 
     android:layout_marginBottom="25dip"/> 

</RelativeLayout> 

不過,如果你想有一個完美的解決方案,你需要設計3種尺寸的按鈕和背景圖片,並將它們放在相應的文件夾drawable-hdpi,drawable-mdpi和drawable-ldpi中(對於平板電腦,從2.2開始,您也可以使用drawable-xhdpi!)。仔細閱讀article並在模擬器中測試您的佈局,以獲得儘可能多的屏幕(從ADT 10.0開始,可以直接從xml中的圖形佈局選項卡預覽不同配置的佈局)。

而且,android:layout_marginTop="160dip"android:layout_marginBottom="25dip"在相對佈局中並不真正有用。我建議你嘗試9-patch picture爲你的背景,只有木板拉伸按鈕(雖然我不知道它的工作是這樣的)。或者,我將與主菜單分開顯示一個單獨的圖片,我將它放在按鈕上方,並僅保留背景樹木和其他所有內容。

0

itz最好爲不同的屏幕尺寸提供不同的佈局。在開發遊戲時,我也有同樣的問題。 你可能提供了佈局,所以你只需提供 layout-large,small和xlarge.and你的佈局的反面你必須提供可繪製的文件夾如hdpi,mdpi,ldpi,xdpi文件夾和你必須保存不同大小的圖像58 * 58,75 * 75,100 * 100以下ü檢查你會得到它。