2012-02-23 73 views
1

Layout在手機上看起來和預期的一樣,在模擬器上看起來不同。我正在使用SDK API 10(Android 2.3)。測試手機是Android 2.3.3(Cyanogen Mod 7)的Motorola Milestone。AppWidget在模擬器和手機上看起來不同 - 轉移查看內容

SDK佈局預覽呈現像仿真器一樣的預覽。

下圖顯示了在右側(通過電話呈現)和在左側(SDK API 10,模擬器和預覽)的意外呈現的預期呈現。

shifted View

什麼是差異的原因,如何解決?刪除邊距和填充(通過將其設置爲0dp TextView1)沒有幫助。

主要佈局(父)

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/test_bg_red" 
     android:padding="20dp" 
> 

    <include 
     android:layout_width="fill_parent" 
     android:layout_height="26dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     layout="@layout/test_child" /> 
/> 

    <include 
     android:layout_width="fill_parent" 
     android:layout_height="26dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     layout="@layout/test_child" /> 

</RelativeLayout> 

子佈局

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="26dp" > 

    <TextView 
     android:id="@+id/textView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" 
     android:layout_marginRight="4dp" 
     android:gravity="top" 
     android:includeFontPadding="false" 
     android:text="42" 
     android:textSize="32dp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/textView2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignBaseline="@+id/textView1" 
     android:layout_toRightOf="@+id/textView1" 
     android:includeFontPadding="false" 
     android:text="TextView2" 
     android:textSize="12dp" /> 

    <TextView 
     android:id="@+id/textView3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignLeft="@+id/textView2" 
     android:layout_alignParentTop="true" 
     android:includeFontPadding="false" 
     android:text="TextView3" 
     android:textSize="10dp" /> 

</RelativeLayout> 

回答

1

相信這是由具有不同縱橫比不同的屏幕引起的。由於手機具有4x4的單元格,而不管物理屏幕的大小如何,每個單元格必須更寬或更窄以適合連續4個。使用DP可以處理密度,但是多或少呈正方形的屏幕仍然需要細胞或多或少爲正方形。這意味着每個單元格的DP數量會有所不同,並導致您的視圖在不同設備上看起來不一樣。

我發現的唯一解決方案是讓佈局儘可能靈活。

相關問題