我想知道在Android中是否可能实现这种渐变色?如果可能,应该怎么做?
http://www.techandall.com/wp-content/uploads/2013/10/techandall_mobile-analytics-UI-concept_preview1.jpg
谢谢,
Bskania。
这里有一个用于创建Android渐变形状的在线工具:
http://angrytools.com/gradient/
点击Android标签,您将获得包含形状的XML代码:
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="linear"
android:centerX="47%"
android:startColor="#FF70C1FF"
android:centerColor="#FFBDC9FF"
android:endColor="#FF734080"
android:angle="45"/>
</shape>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<gradient
android:type="radial"
android:centerX="50%"
android:centerY="50%"
android:startColor="#FF70C1FF"
android:centerColor="#FFBDC9FF"
android:endColor="#FF734080"
android:gradientRadius="47"/>
</shape>
int startColor=Color.parseColor("#a6c1de");
//you can add as many gradient colors as you want here
//and include it in the int array while initializing GradientDrawable
int endColor=Color.parseColor("#aa82b7");
GradientDrawable mDrawable=new GradientDrawable(Orientation.LEFT_RIGHT,
new int[] {startColor,endColor});
LinearLayout mLayout=(LinearLayout)findViewById(R.id.your_id);
mLayout.setBackgroundDrawable(mDrawable);
new int[] startColor,centerColor, endColor}
- makata您无法像图像中那样使用多种颜色创建Gradient
,其中两种颜色呈线性。因此,您应该使用图像而不是渐变。