带有XML的多色描边图像 [英] Multi color Stroke image with XML

查看:304
本文介绍了带有XML的多色描边图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以借助XML创建多色笔画?我想在此处创建确切的视图.

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

谢谢

推荐答案

您可以通过创建带有渐变的可绘制形状并将其设置为父级背景来使用技巧:

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(以res/可绘制格式):

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:

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

这篇关于带有XML的多色描边图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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