2011-08-18 54 views
1

我有一個帶自定義android:背景和上面的EditText(在LinearLayout中)的Button。我希望Button佔用大約30%的可用屏幕,EditText佔用其餘的部分。我使用layout但是,我的按鈕的自定義圖像需要寬度以與高度相同的比例進行縮放,因此不會被拉伸。我怎麼做? 到目前爲止,我有:使用layout_weight時保持視圖對象的比例

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:background="@drawable/woodbackground"> 
    <EditText 
     android:id="@+id/editText1" 
     android:layout_height="0dip" 
     android:layout_weight="2" 
     android:layout_width="fill_parent" 
     android:layout_margin="10dip"> 
    </EditText> 
    <Button 
     android:layout_height="0dip" 
     android:background="@drawable/sayit_button" 
     android:layout_width="wrap_content" 
     android:id="@+id/button1" 
     android:layout_weight="1" 
     android:layout_gravity="center"> 
    </Button> 
</LinearLayout> 

感謝您的幫助,

菲爾。

回答

0

提出了一個非常類似的問題,其中接受的解決方案基本上是用FrameLayout對背後的背景進行分層。不太理想,但可能是您唯一的選擇:Android: Scale a Drawable or background image?

而這可能根本沒有任何幫助,但您可以探索9繪製可修補程序的功能。一個可繪製的9補丁基本上是一個可繪製的(比如你的背景圖形),它有一個特殊的不可見邊框,指定它將在哪裏展開。更多info on 9 patch9 patch tool