【问题标题】:Android shape border with gradient and middle transparent带有渐变和中间透明的Android形状边框
【发布时间】:2016-10-29 19:39:35
【问题描述】:

我需要创建一个圆角边框,其中带有渐变的边框。enter link description here 正在工作。但是我的页面使用的图像作为背景,也带有渐变。我需要从字段中间显示背景图像。我想创建如下图:

【问题讨论】:

    标签: android android-layout


    【解决方案1】:

    round_background.xml

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="rectangle">
    <stroke
        android:width="4dp"
        android:color="@color/transparent" />
        <gradient
            android:startColor="#374533"
            android:centerColor="#432727"
            android:endColor="#222430"
            android:angle="135"/>
        <corners android:radius="10dp" />
    </shape>
    

    round_border.xml

    <shape xmlns:android="http://schemas.android.com/apk/res/android">
    
    <gradient
        android:startColor="#efe301"
        android:centerColor="#7dc17b"
        android:endColor="#01dae6"
        android:angle="180"/>
    <corners android:radius="10dp" />
    

    result_drawable.xml

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

    在这里,您可以在 round_background.xml 中设置 android:width="4dp" 来设置边框的大小。在你想要的地方使用结果 result_drawable.xml .. 享受。 :}

    【讨论】:

    • 我的背景也是渐变色的,怎么搭配背景色呢?
    • 为我工作的自定义标签布局
    • 那不是想要的结果,内部背景不是真正透明的
    • 您需要为背景上的每个位置使用不同的 round_background.xml。这没有意义..
    猜你喜欢
    • 1970-01-01
    • 2014-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多