Android的 - 使XML的箭头形状 [英] Android - make an arrow shape with xml

查看:4682
本文介绍了Android的 - 使XML的箭头形状的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想为我的形状的按钮,像这样的

I want to make a button for my shape like this one

有没有办法用XML做到这一点? 比如设置一些点,在我的情况下,我有5个。

Is there a way to do this with xml ? Like setting some points, in my case I have 5..

推荐答案

你需要的是建立一个的 形状xml文件 的在您的项目的 绘制-XXX 的文件夹,然后用这个形状背景的按钮。

What you need is to create a shape xml file in your project's drawable-xxx folder and then use this shape as background for a button.

下面是所谓的形文件的 arrow_shape.xml 的:

Here is the shape file called arrow_shape.xml:

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

<item>
    <shape android:shape="rectangle">
        <size 
            android:width="100dp"
            android:height="40dp" />
        <solid android:color="#5EB888" />
        <corners android:radius="0dp"/>
    </shape>
</item>

<item
    android:top="-40dp"
    android:bottom="65dp"
    android:right="-30dp">
    <rotate
        android:fromDegrees="45">
        <shape android:shape="rectangle">
            <solid android:color="#ffffff" />
        </shape>
    </rotate>
</item>

<item
    android:top="65dp"
    android:bottom="-40dp"
    android:right="-30dp">
    <rotate
        android:fromDegrees="-45">
        <shape android:shape="rectangle">
            <solid android:color="#ffffff" />
        </shape>
    </rotate>
</item>

</layer-list>

然后把它作为按钮的背景,例如:

Then use it as button's background, for example

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/arrow_shape"/>

下面是截图:

上的 层列表 的你可以找到<一个更多信息href="http://developer.android.com/guide/topics/resources/drawable-resource.html#LayerList">here.

编辑:

请记住,虽然我用的某些值形状的宽度和高度。如果您更改那些你可能需要改变的 顶部,底部和右侧值属性 的。因此,在这种情况下考虑使用不同的值,你的项目的 的目录。

Keep in mind though that I used certain values for the shape's width and height. If you change those you might need to change the values of the top, bottom and right attributes. So, in that case consider using different values in your project's values directory.

这篇关于Android的 - 使XML的箭头形状的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆