3

我正在尝试重复按钮。我可以重复常规背景类型。但我无法使用重复的 xml 文件找到右、左和中心。

如果您知道 xml 文件的一些解决方案,请帮助我。

提前致谢

我使用的重复xml文件是

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
        <bitmap
            android:src="@drawable/barslice"
            android:tileMode="repeat"
            android:dither="true"/>
</item>

我需要的按钮是: 左角

中央

右上角

我需要的完整按钮

4

3 回答 3

3

您甚至可以在不使用图像的情况下获得圆角渐变按钮。

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true" >
        <shape>
            <solid
                android:color="#449def" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="3dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
    <item>
        <shape>
            <gradient
                android:startColor="#449def"
                android:endColor="#2f6699"
                android:angle="270" />
            <stroke
                android:width="1dp"
                android:color="#2f6699" />
            <corners
                android:radius="4dp" />
            <padding
                android:left="10dp"
                android:top="10dp"
                android:right="10dp"
                android:bottom="10dp" />
        </shape>
    </item>
</selector>

只需将其设置为按钮、文本视图或任何您想要的背景

于 2012-02-07T07:14:06.807 回答
1

这将由 9 个补丁图像很好地处理。你会有这样的图像

9 补丁图像

android会自动处理它。只需将其设置为任何按钮的背景。

注意:其他状态的图像,如pressed,focuseddisabled应提供,否则不会改变按钮状态。

于 2012-02-07T07:26:35.187 回答
0

您可以使用 9-patch 图像。检查以下链接。

http://developer.android.com/guide/topics/resources/drawable-resource.html#NinePatch

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

于 2012-02-07T07:14:03.473 回答