自定义箭头没有图像:机器人 [英] Custom arrows without image: Android

查看:186
本文介绍了自定义箭头没有图像:机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我跟着这个教程:<一href=\"http://looksok.word$p$pss.com/2013/08/24/android-triangle-arrow-defined-as-an-xml-shape/\">http://looksok.word$p$pss.com/2013/08/24/android-triangle-arrow-defined-as-an-xml-shape/

本教程是用于创建自定义箭头加/减键,而无需使用图像。箭头的形状是细然而向上箭头定位成其在按钮视图底部和向下箭头基部被定位成是碱在按钮视图的顶部。在otherwords,箭头不正确对齐。

我想知道,是否有某种y轴的按键观点偏移,可以用来更好地定位箭头?在code我是:

 &LT;的RelativeLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    的xmlns:工具=htt​​p://schemas.android.com/tool​​s
    机器人:layout_width =match_parent
    机器人:layout_height =match_parent&GT;    &LT;按钮
        机器人:ID =@ + ID / arrow_up
        机器人:layout_width =75dp
        机器人:layout_height =75dp
        机器人:背景=@绘制/ custom_arrow/&GT;    &LT;按钮
        机器人:ID =@ + ID / arrow_down
        机器人:layout_width =75dp
        机器人:layout_height =75dp
        机器人:旋转=180
        机器人:layout_toRightOf =@ ID / arrow_up
        机器人:背景=@绘制/ custom_arrow/&GT;
&LT; / RelativeLayout的&GT;

该custon_arrow.xml是:

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT;层列表的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android&GT;
    &LT;项目&GT;
        &LT; - 安卓!pivotX = - 40% - &GT;
        &LT;旋转
            机器人:fromDegrees =45
            机器人:toDegrees =45
            机器人:pivotX = - 20%
            机器人:pivotY =88%&GT;
            &LT;形状
                机器人:形状=矩形&GT;
                &LT;行程机器人:颜色=@色/透明的机器人:宽=5DP/&GT;
                [固体
                    机器人:颜色=@色/ grey_shade/&GT;
            &LT; /形状&GT;
        &LT; /旋转&GT;
    &LT; /项目&GT;
&LT; /层列表&gt;


解决方案

请您的 marginLeft 属性是一致的(一个是3DP另一种是5DP)。

SO! (以后看到图片)你在谈论的纵向对齐!

我觉得你可以轻松地添加一些paddingBottom会到向上的箭头,paddingTop的向下箭头。

OK,这是一个廉价和肮脏的伎俩,但...

...这个答案肯定是更好的:<一href=\"http://stackoverflow.com/questions/1532876/android-combining-text-image-on-a-button-or-imagebutton\">look

I followed this tutorial: http://looksok.wordpress.com/2013/08/24/android-triangle-arrow-defined-as-an-xml-shape/

The tutorial is for creating custom arrows as increment/decrement buttons without having to use images. The shape of the arrows are fine however the up arrow is positioned with its base at the bottom of the button view and the down arrow is positioned with is base at the top of the button view. In otherwords, the arrows are not aligned properly.

I was wondering, is there some sort of y-axis offset for button views that can be used to position the arrows better? The code I have is:

<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>

The custon_arrow.xml is:

<?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>

解决方案

Make your marginLeft attributes consistent (one is 3dp the other one is 5dp).

SO! (after seeing the picture) you were talking about vertical alignment!

I think you can easily add some paddingBottom to the up arrow and paddingTop to the down arrow.

OK, it's a cheap and dirty trick, but...

... this answer is surely better: look

这篇关于自定义箭头没有图像:机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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