【问题标题】:How can I create a custom gradient in android?如何在android中创建自定义渐变?
【发布时间】:2014-06-25 07:46:45
【问题描述】:

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

谢谢, 布斯卡尼亚。

【问题讨论】:

    标签: android colors gradient shape


    【解决方案1】:

    这里有一个为 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>
    

    【讨论】:

    • 实际上它给出了线性渐变颜色形状,但正如您在图像中看到的那样,它并不完全是线性渐变。如果您选择两种颜色,则应该从上到下,每种颜色从浅到深并排。
    【解决方案2】:
    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}
    【解决方案3】:

    您不能使用多种颜色来创建Gradient,就像您的图像中两种颜色呈线性一样。所以你应该使用图像而不是渐变。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多