安卓:按钮行程仅左侧 [英] Android: Stroke Left Side of Button Only

查看:226
本文介绍了安卓:按钮行程仅左侧的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想借鉴使用中风按钮突出3D线路。我该怎么做呢?从我custom_button.xml选择以下块是默认按钮状态。我期待按钮的背景填充有蓝色渐变而粉红色(只是用于测试!)线出现在该按钮的左侧

I'm trying to draw highlight "3D" lines on a button using a stroke. How do I do this? The below chunk from my custom_button.xml selector is for the default button state. I'm expecting the background of the button to be filled with a blue gradient but a pink (just for testing!) line to appear on the left side of the button.

我应该使用如下图所示的第二层列表?
我如何获得该行出现在按钮只是左边?在present粉红色的线出现围绕整个按钮,它用黑色而不是蓝色渐变填充的按钮。这是因为第二项的默认颜色为黑色..尽管我试图将其设置为透明?

Should I be using a layer-list as shown below? How do I get the line to appear on just the left of the button? At present the pink line appears around the entire button and it fills the button with black instead of the gradient blue. Is this because the second item's default color is black.. even though I am trying to set it to transparent?


    

<shape>
    <gradient
        android:endColor="@color/blue2"
        android:startColor="@color/blue25"
        android:angle="270" />
    <stroke
        android:width="3dp"
        android:color="#00FFFF" />
    <corners
        android:radius="3dp" />
    <padding
        android:left="10dp"
        android:top="10dp"
        android:right="10dp"
        android:bottom="10dp" />
</shape>

<item android:left="1dp">
    <shape>
       <solid android:color="@android:color/transparent" /> 
       <stroke android:width="1dp" android:color="#FF8888" />
   </shape>
</item>

</layer-list>

下面是我所得到的(顶部)和我所希望得到(底部)的图像。我只使用这些颜色,用于测试目的! :-)

Below is an image of what I get (on top) and what I expect to get (on the bottom). I'm only using these colours for test purposes! :-)

推荐答案

您可以试试这个

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

    <item
        android:bottom="-2dp"
        android:right="-2dp"
        android:top="-2dp">
        <shape>
            <solid android:color="@android:color/transparent" />

            <stroke
                android:width="1dp"
                android:color="#FF8888" />
        </shape>
    </item>
    <item
        android:drawable="@drawable/shape2"
        android:left="1dp">
    </item>

</layer-list>

其中, @绘制/ shape2 是你在上面

结果:

这篇关于安卓:按钮行程仅左侧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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