2012-03-19 76 views
0

我是新來的Android我需要實現具有背景圖像大小的按鈕我如何實現這一點?如何自動調整按鈕的大小

在那種我要調整按鈕的大小根據背景圖像

+0

如果您實現具有背景圖像大小的按鈕,您將獲得什麼優勢?那麼背景圖像會變得可見嗎? – 2012-03-19 13:44:08

+0

查看http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch。這是Android中按鈕背景圖像的最佳做法。如果這不符合您的要求,我會問像Paresh Mayani一樣的問題。 – KarlKarlsom 2012-03-19 13:48:10

+0

@PareshMayani是的背景圖像應該比之後可見,我會在那之後動態地改變背景圖像,並且按鈕的大小應該相應地改變。 – NIKHIL 2012-03-20 04:41:52

回答

1
<LinearLayout android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/image"> 

    <Button android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
     android:id="@+id/button1" 
     android:text="Button" /> 

</LinearLayout> 

它會爲你工作。

0

當你在按鈕設置圖像則必須設置

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

,當我們把它layout_width,layout_height按鈕,然後自動重新大小相同的圖像尺寸,所以不要爲強說愁。你可以像下面的例子那樣按鈕。

<Button android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/button1" 
     android:text="Button" 
     android:background="@drawable/image"/>