2014-11-06 61 views
0

我希望把PNG图像按钮上,我试图安卓背景,但PNG通吃的按钮,我想到底是什么标志使用PNG按钮上这样我想把图像按钮上

enter image description here

的信息标志是我的PNG和“约”来自按钮上的文字

+0

发布你试过的东西.. – 2014-11-06 07:43:00

+0

另一种方法是使用RelativeLayout,将ImageView作为其子。现在把这个RelativeLayout当作一个按钮。 – schnill 2014-11-06 07:49:27

回答

0

可以使用FrameLayout。在一个FrameLayout中,z索引是通过在其中添加项的顺序定义,例如

<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="@string/button_text" /> 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/my_drawable" 
     android:scaleType="fitCenter"/> 
</FrameLayout> 

在这种情况下,ImageView将在Button的顶部可以得出,沿着的底部中心Button

3

u可以使用这样的:

android:drawableTop="@drawable/SomeIcon" 

,那么你会得到:

<Button 
android:id="@+id/damage" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:layout_gravity="center_horizontal" 
android:text="about" 
android:drawableTop="@android:drawable/ic_menu_info_details"/> 

enter image description here

它为我工作:)

1

您可以检查this thread 基本上,您可以使用:

<ImageButton 
    android:id="@+id/ImageButton01" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/album_icon" 
    android:background="@drawable/round_button" /> 

正如线程所说。

1

RelativeLayout,将ImageView置于其中。现在在RelativeLayout上设置onClickListener。 通过这种方式,你可以创建更复杂的按钮。

<RelativeLayout android:id="@+id/your_btn_id" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" /> 
</RelativeLayout> 
0

可以使用

android:drawableTop 

把绘制在按钮的顶部,并使用适当的填充,使其定位好。

0
<Buttton 
     android:layout_width="99dp" 
     android:layout_height="99dp" 
     android:background = "@drawable/bg" /> 

bg是您的自定义图像。