Multi color Stroke image with XML

我与影子孤独终老i 提交于 2019-12-12 03:23:30

问题


Does it possible to create multi-color stroke with the help of XML? I want to create exact view attached here.

Thanks


回答1:


You could use a trick by creating a drawable shape with gradient and make it a parent's background... something like this:

gradient_stroke.xml (in res/drawable):

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
    <shape  android:shape="rectangle" >
        <gradient
                     android:angle="180"
                     android:startColor="#fff96200"
                     android:centerColor="#fffff60f"
                     android:endColor="#fff96200"
                     android:centerX="50%"

                     >
             </gradient>
        <corners android:radius="5dp"></corners>
    </shape>
</item>

your_view.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:layout_width="wrap_content"
          android:padding="2dp"
          android:background="@drawable/gradient_stroke"
          android:layout_height="wrap_content">

<Button android:text="Submit"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/green"
        android:id="@+id/button"/>
</LinearLayout>

Just an idea - play around with it to get desired values...



来源:https://stackoverflow.com/questions/27692701/multi-color-stroke-image-with-xml

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!