Android gradient NEVER works (always banding)

社会主义新天地 提交于 2021-02-05 06:01:06

问题


I tried to add a (radial) gradient as background (in Android 4.0), either as background image or programmatically but none of them never works. I can only test it in emulator, but I guess it's the same on a 4.0 device.

These solutions don't work:

  • Placing in raw folder. (Disable Android resource / image / png optimization)
  • Making a proxy xml with dithering and anti aliasing true, as well as saving opacy of png to 99%. (android:dither="true" does not dither, what's wrong?)
  • Overriding onAttachedToWindow (Android: Using linear gradient as background looks banded)
  • Moving to hdpi folder (gradient on Gingerbread)
  • Making gradient programmatically (http://crazygui.wordpress.com/2010/09/05/high-quality-radial-gradient-in-android/)

I guess I tried some more things but maybe someone has an idea how to build a working gradient as background?

My current code looks like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".SplashScreen">

    <ImageView
        android:id="@+id/imageViewLogo"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:contentDescription="@string/desc_string"
        android:scaleType="centerCrop"
        android:src="@drawable/background_image" />

</RelativeLayout>

and background_image.xml

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/background_image"
    android:antialias="true"
    android:dither="true"
    android:src="@drawable/bg_portrait" />

回答1:


Obviously it's just the emulator. On a real device it looks good.




回答2:


Try this link mate, http://developer.android.com/reference/android/graphics/RadialGradient.html

override on draw function to draw circle using canvas object



来源:https://stackoverflow.com/questions/21985385/android-gradient-never-works-always-banding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!