没有图片的自定义箭头:Android

por*_*der 9 xml android android-custom-view

我遵循了这个教程:http://looksok.wordpress.com/2013/08/24/android-triangle-arrow-defined-as-an-xml-shape/

本教程用于创建自定义箭头作为递增/递减按钮,而无需使用图像.箭头的形状很好但是向上箭头的位置使其底部位于按钮视图的底部,而向下箭头的底部位于按钮视图的顶部.换句话说,箭头没有正确对齐.

在此输入图像描述

我想知道,按钮视图是否有某种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>
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

Elh*_*aky 16

<TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="?"/>
Run Code Online (Sandbox Code Playgroud)

要么

<TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="?"/>
Run Code Online (Sandbox Code Playgroud)

你可以在这里获得更多选择.


zed*_*zed 13

可以使用路径轻松完成:

<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="32dp"
        android:height="24dp"
        android:viewportWidth="32.0"
        android:viewportHeight="24.0">
    <path android:fillColor="#e4e4e8"
          android:pathData="M0 0 h32 l-16 24 Z"/>
</vector>
Run Code Online (Sandbox Code Playgroud)

箭头