2012-11-08 25 views
0

我有一個背景PNG的RelativeLayout。背景PNG中有一個標題。在RelativeLayout中,我將小部件放置在這個頭部中。Android:在RelativeLayout中縮放和控件的位置和背景圖片

當這個擴展到更大的設備時,問題就會出現:背景PNG中的頭部伸展,導致頭部中的部件位置過高。因爲我在「dp」中指定了我的相對佈局定位,所以我希望這些小部件可以根據背景圖像的縮放比例進行重新定位並自動歸位。

這裏的簡化版本我的RelativeLayout的:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/RelativeLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:paddingBottom="26dp" 
    android:paddingLeft="12dp" 
    android:background="@drawable/home_bg" 
    android:paddingRight="12dp" 
    tools:context=".HomeActivity" > 

    <TextView 
     android:id="@+id/welcome_tv" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="142dp" 
     android:text="@string/home_11" 
     android:textColor="@color/tile_points_white" 
     android:textSize="20sp" /> 

</RelativeLayout> 

我知道我可以修復的標題,高度在9補丁背景PNG(這就是我現在做的),但我寧願我的頭規模也是垂直的。

如何指定我的小部件應該按比例重新定位到背景PNG的縮放比例?

乾杯, 安德烈

+0

也許你正在努力實現將有助於什麼的截圖... –

回答

0

嘗試改變

android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 

android:layout_width="wrap_content" 
    android:layout_height="wrap_content"