Android 透明黑色渐变形状可绘制颜色代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23604361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Transparent black gradient shape drawable color code
提问by Detoxic-Soul
<?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>
This is the code I tried but it ends up as pure black.
这是我试过的代码,但它最终是纯黑色的。
回答by Phant?maxx
What about this gradient? Full transparency at top to 50% transparent black at bottom
这个渐变呢?顶部全透明至底部 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>
回答by FD_
Try this instead:
试试这个:
<?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>
回答by Madi
Add your class this code
将此代码添加到您的班级
GradientDrawable gd = new GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, new int[] {endColor,startColor}); gd.setCornerRadius(0f); layout.setBackgroundDrawable(gd);
Hope this will help!
GradientDrawable gd = new GradientDrawable( GradientDrawable.Orientation.TOP_BOTTOM, new int[] {endColor,startColor}); gd.setCornerRadius(0f); layout.setBackgroundDrawable(gd);
希望这会有所帮助!
回答by Dmitriy Melekhov
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>