Android: używanie gradientu liniowego jako tła wygląda na pasmowe

Próbuję zastosować gradient liniowy do mojego ListView. To jest treść mojego rysowalnego xml:

 <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient 
        android:startColor="#3A3C39" 
        android:endColor="#181818"
        android:angle="270"
     />
    <corners android:radius="0dp" />
</shape>

Więc zastosuję go do mojego ListView za pomocą:

android:background="@drawable/shape_background_grey"

To działa, ale wygląda bardzo "banded" na emulatorze i na prawdziwym urządzeniu zbyt.

Czy jest jakiś sposób, aby zmniejszyć to "zachowanie"?
Author: kiamlaluno, 2010-05-28

7 answers

Jak sugeruje Romain Guy:

listView.getBackground().setDither(true);

Rozwiązuje mój problem

Jeśli to nie wystarczy, szczególnie dla urządzeń AMOLED i/lub hdpi, spróbuj tego:

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    Window window = getWindow();
    window.setFormat(PixelFormat.RGBA_8888);
}
 84
Author: Francesco Laurita,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-11 12:52:04

Możesz po prostu włączyć dithering na swoim Rysowalnym obiekcie.

 39
Author: Romain Guy,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-05-28 17:36:05

Dodaj to do swojej aktywności:

@Override
public void onAttachedToWindow() {
    super.onAttachedToWindow();
    Window window = getWindow();
    window.setFormat(PixelFormat.RGBA_8888);
}
 9
Author: Miša Peić,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-06-10 18:03:14

Dla mnie na HTC Desire działa tak

window.getDecorView().getBackground().setDither(true);
 3
Author: Sebastian,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-11-10 09:29:59

Dla mnie banding zniknął, gdy ustawiłem android: useLevel= "true" na gradiencie: gradient_dark.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="#464646"
        android:endColor="#323232"
        android:angle="270"
        android:type="linear"
        android:useLevel="true"
         />
</shape>

Ale najpierw próbowałem użyć listy warstw z" szumem", aby usunąć banding, pomaga, ale nadal jest pewne banding.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/gradient_dark"/>
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/noise_repeater"
            android:tileMode="repeat" />
    </item>

</layer-list>

The "noise_repeater" drawable I created and used

Tutaj wpisz opis obrazka

 2
Author: TouchBoarder,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2014-02-13 12:05:56

Jeśli ustawienie dither i RGBA_888 nie pomaga w niektórych telefonach, rozwiązaniem może być ustawienie elementu layerType na software, aby wyłączyć akcelerację sprzętową

android:layerType="software"
To naprawiło mój problem z telefonem Samsung S5.
 2
Author: peter.bartos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-03-17 16:11:10

Jedyną rzeczą, która zadziałała dla mnie, było ustawienie lekko przezroczystego kanału alfa zarówno na startColor, jak i endColor.

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

Wpadłem na pomysł, aby spróbować z tego innego więc pytanie: android:dither="true" nie dither, co jest nie tak?

 0
Author: Greg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 11:54:33