我按照这个教程进行操作:http://looksok.wordpress.com/2013/08/24/android-triangle-arrow-defined-as-an-xml-shape/
该教程是为了创建自定义箭头作为增量/减量按钮而无需使用图像。箭头的形状很好,但向上箭头在按钮视图底部以其基础为位置,向下箭头在按钮视图顶部以其基础为位置。换句话说,箭头未正确对齐。
我想知道,是否有某种y轴偏移量可用于更好地定位箭头按钮?我拥有的代码是:
我想知道,是否有某种y轴偏移量可用于更好地定位箭头按钮?我拥有的代码是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/arrow_up"
android:layout_width="75dp"
android:layout_height="75dp"
android:background="@drawable/custom_arrow" />
<Button
android:id="@+id/arrow_down"
android:layout_width="75dp"
android:layout_height="75dp"
android:rotation="180"
android:layout_toRightOf="@id/arrow_up"
android:background="@drawable/custom_arrow" />
</RelativeLayout>
custon_arrow.xml文件是:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<!-- android:pivotX="-40%" -->
<rotate
android:fromDegrees="45"
android:toDegrees="45"
android:pivotX="-20%"
android:pivotY="88%" >
<shape
android:shape="rectangle" >
<stroke android:color="@color/transparent" android:width="5dp"/>
<solid
android:color="@color/grey_shade" />
</shape>
</rotate>
</item>
</layer-list>