Android 带形状的多色线条
我正在尝试用3种或更多颜色来完成单线背景,我想知道是否可以使用xml形状,或者我必须使用9个补丁?我是一个对形状有点陌生的人,我花了一上午的时间试图完成我想要的东西,但什么都没有 以下是我想要实现的目标: 我已经尝试过这个渐变形状,但它只采用了开始颜色Android 带形状的多色线条,android,shapes,nine-patch,Android,Shapes,Nine Patch,我正在尝试用3种或更多颜色来完成单线背景,我想知道是否可以使用xml形状,或者我必须使用9个补丁?我是一个对形状有点陌生的人,我花了一上午的时间试图完成我想要的东西,但什么都没有 以下是我想要实现的目标: 我已经尝试过这个渐变形状,但它只采用了开始颜色 <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <!-- This is the line --> <item>
<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>
解决方案更新
除了山姆提供的答案之外,我发现9.png是解决我问题的最佳答案。我只需创建一个带有3种颜色的png,然后应用9个补丁并完成:D我使用了这个工具weblookandfeel.com/nine-patch-editor它只需在应用程序中打开图像并保存,你就拥有了9.png。你可以尝试使用这个工具来获得你想要的颜色, 然后水平排列,其中一个想法可以是,创建三个可绘制表格,并使用线性布局进行排列
<?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>
图层列表
会将一个形状/项目置于其他形状/项目之上。是的,你是对的,这是一种方法,但很难,我简单地用3种颜色创建一个png,我想用9个补丁创建一个9.png,瞧!完成了:D 9个补丁这太棒了:D通过我使用这个工具的方式,只需在应用程序中打开图像并保存,你就有了9.png,但我会接受你的答案,因为这是一个有效的解决方案,谢谢;)