我想用3种或更多种颜色完成单行背景,我想知道它是否可以用于xml形状,或者我必须使用9个补丁?我是一个形状新颖的新手,我整个上午都在努力完成我想要的东西,但一无所获。

以下是我要实现的目标:



我已经尝试过使用渐变绘制此形状,但它仅假定起始颜色

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- This is the line -->
<item>
      <shape>
            <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="1dp"/>
            <solid android:color="#868686" />
      </shape>
</item>
<!-- This is the main color -->
<item>
     <shape>
         <solid android:color="@android:color/white" />
     </shape>
</item>




解决方案更新

除了SAM提供的答案外,我发现9.png是解决我的问题的最佳答案。我简单地用3种颜色创建一个png,然后应用9个色标和DONE:D我已经使用了此工具weblookandfeel.com/九补丁编辑器,就像在应用程序中打开图像并保存一样简单,您拥有9.png。

最佳答案

您可以尝试使用此工具获取所需的颜色,
http://angrytools.com/gradient/

然后水平排列,其中一个想法是,创建三个可绘制对象并使用线性布局进行排列

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image1"/>
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image2"/>
    <ImageView android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/image3"/>

</LinearLayout>

07-28 01:52
查看更多