如何在android中创建自定义渐变?

问题描述 投票:3回答:3

我想知道这种渐变颜色在android中是否可行?如果可能的话怎么样? http://www.techandall.com/wp-content/uploads/2013/10/techandall_mobile-analytics-UI-concept_preview1.jpg

谢谢,Bskania。

android colors gradient shape
3个回答
1
投票
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);

6
投票

在这里,您有一个在线工具,用于为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>

0
投票

您无法使用许多颜色创建Gradient,例如图像中两种颜色呈线性关系。所以你应该使用Image而不是渐变。

© www.soinside.com 2019 - 2024. All rights reserved.