透明黑色渐变形状可绘制颜色代码

时间:2014-05-12 08:33:26

标签: android gradient shape android-drawable

gradient for view pager indicator

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#000"
        android:centerColor="#00000000"
        android:endColor="#000"
        android:angle="270"
        android:dither="true"
     />
</shape>

这是我尝试的代码,但最终却是纯黑色。

4 个答案:

答案 0 :(得分:39)

这个渐变怎么样?底部完全透明,底部为50%透明黑色

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#00000000"
        android:endColor="#80000000"
        android:angle="270"
        android:dither="true"
     />
</shape>

答案 1 :(得分:1)

请改为尝试:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#00000000"
        android:endColor="#FF000000"
        android:angle="270"
        android:dither="true"
     />
</shape>

答案 2 :(得分:1)

添加此类代码

  

GradientDrawable gd = new GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, new int[] {endColor,startColor}); gd.setCornerRadius(0f); layout.setBackgroundDrawable(gd);   希望这会有所帮助!

答案 3 :(得分:0)

In my case it works great:


   <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android">
        <gradient
            android:angle="270"
            android:endColor="@android:color/transparent"
            android:startColor="#000000" />
    </shape>