如何在Android中使用XML形状创建向右箭头(雪佛龙)? [英] How to create a right facing arrow (chevron) using XML shapes in android?
本文介绍了如何在Android中使用XML形状创建向右箭头(雪佛龙)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何像这样在android中使用xml形状创建向右箭头?
How to create a right facing arrow using xml shapes in android like this??
推荐答案
我遇到了类似的问题.这是我解决的方法:
I've had a similar problem. Here's how I solved it:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape>
<solid android:color="@android:color/transparent"/>
<size android:width="2dp" android:height="50dp"/>
</shape>
</item>
<item android:bottom="20dp">
<rotate
android:fromDegrees="-45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="@android:color/black"/>
<corners
android:radius="1dp"
android:bottomRightRadius="0dp"
android:bottomLeftRadius="0dp"/>
</shape>
</rotate>
</item>
<item android:top="20dp">
<rotate
android:fromDegrees="45"
android:toDegrees="45">
<shape android:shape="rectangle">
<solid android:color="@android:color/black"/>
<corners
android:radius="1dp"
android:topRightRadius="0dp"
android:topLeftRadius="0dp"/>
</shape>
</rotate>
</item>
</layer-list>
第一项是用于扩展可绘制对象的空形状.然后,我使用了2个矩形.他们每个人都有2个倒角的面.
The first item is an empty shape to expand the drawable. Then, I've used 2 rectangles. Each of them has 2 sides rounded.
您需要通过ImageView
使用此可绘制对象:
You need to use this drawable via an ImageView
:
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:src="@drawable/arrow"
android:contentDescription="@string/arrow_descriptor"/>
结果如下:
注意:AndroidStudio不会渲染不同的角尺寸,但可以在设备上正确显示.
Note: AndroidStudio doesn't render different corner sizes, but it shows up properly on devices.
这篇关于如何在Android中使用XML形状创建向右箭头(雪佛龙)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文