2012-03-19 71 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"/>