سؤال

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>

This is the code I tried but it ends up as pure black.

هل كانت مفيدة؟

المحلول

What about this gradient? Full transparency at top to 50% transparent black at bottom

<?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>

نصائح أخرى

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>

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!

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>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top