2012-06-23 52 views
0

我花了最後幾天嘗試進行佈局。Android小部件相對佈局

他們的佈局看起來不錯,我的手機與480x800的屏幕,但是我的手機與540x960屏幕搞砸了。

我用dp期望它可以通過密度進行縮放。

什麼問題?

這是我的佈局xml代碼。

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

    android:layout_margin="15dip" 
    android:background="@drawable/gshock5"> 



    <TextView 
     android:id="@+id/widgetday" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:layout_marginRight="50dip" 
     android:layout_marginTop="95sp" 
     android:layout_centerInParent="true" 
     android:text="DAY" 
     android:textColor="#003300" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textStyle="bold"/> 


    <TextView 
     android:id="@+id/widget1label" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/widgetday" 
     android:layout_centerHorizontal="true" 
     android:clickable="true" 

     android:textColor="#003300" 
     android:text="Error" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textStyle="bold"/> 

    <RelativeLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 

     android:layout_centerHorizontal="true" 
     android:layout_marginTop="210dip"> 

     <Button android:text="Click Me!" 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 


     /> 


    </RelativeLayout> 


</RelativeLayout> 
+0

密度真的是唯一的區別嗎?如果兩個設備的分辨率*和*屏幕尺寸不同,那麼單獨放置就不會使它們顯得平等。 – Ixx

+0

btw你正在使用sp的widgetday layout_marginTop。據我所知,這隻用於文本大小...但這不應該與您的問題有關。 – Ixx

+0

發佈此佈局的「好」和「壞」版本的屏幕截圖可能很有用 –

回答

0

嘗試使用線性佈局。導致設備改變時,確定它被縮放。但是,當使用相對佈局時,它們會相對排列,然後縮放,這可能會讓事情變得混亂。

0
<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_margin="15dip" 
    android:background="@drawable/gshock5" 
    android:orientation="vertical" > 

    <TextView 
     android:id="@+id/widgetday" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginRight="50dip" 
     android:layout_marginTop="95dip" 
     android:text="DAY" 
     android:textAppearance="?android:attr/textAppearanceSmall" 
     android:textColor="#003300" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/widget1label" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/widgetday" 
     android:layout_centerHorizontal="true" 
     android:clickable="true" 
     android:text="Error" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:textColor="#003300" 
     android:textStyle="bold" /> 

    <Button 
     android:id="@+id/button" 
     android:layout_centerHorizontal="true" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_below="@id/widget1label" 
     android:text="Click Me!" /> 

</RelativeLayout> 

這可能會解決您的問題。嘗試使用UI的最小布局。