0

我正在尝试使按钮的角变圆,并设置背景图像。虽然我能够实现圆角按钮,但不能将图像设置为背景。当我尝试android:drawableTop:@drawable/filename时,按钮再次转换为其默认形状,文本位于图像下方,但我希望图像作为背景,那么如何将东西(圆角和背景图像)应用于按钮?

我创建了一个名为button_shapedrawable 的 xml 文件;它的代码是:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" 

android:shape="rectangle"
>

<solid android:color="#ffffff"
     />

<corners
    android:bottomLeftRadius="20dp"
    android:bottomRightRadius="20dp"
    android:topLeftRadius="20dp"
    android:topRightRadius="20dp" />
<stroke android:width="3dp" android:color="#000000" />
</shape>

我放置按钮的主要xml文件代码是:

<Button
    android:id="@+id/button1"
    android:layout_width="150dp"
    android:layout_height="40dp"
    android:layout_marginTop="179dp"
    android:background="@drawable/button_shape"
    android:text="Button"
    android:textColor="#000000" 
    />

请帮我解决一下这个。

4

2 回答 2

0

在形状上使用它

solid android:color="@android:color/transparent" />

和 imageview 应该是

<ImageView
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"  android:scaleType="fitXY"   android:background="@drawable/shape"     
     android:src="@drawable/yourimage" />
于 2012-08-10T11:40:34.793 回答
0

使用此 background.xml 放入 Drowable 并设置在 Button android:background="@drawable/ background" 和 ovel_shape 是可绘制的 xml 文件,您可以在其中放置圆角的代码

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

    <item
        android:id="@+id/rounded_corn"
        android:drawable="@drawable/ovel_shape"/>
    <item
        android:id="@+id/background_img"
        android:drawable="@drawable/image"/>

</layer-list>
于 2012-09-03T05:45:52.560 回答