http://stackoverflow.com/questions/8417608/awful-background-image-quality-in-android/8417703#8417703

First of all, make sure that your original image looks good so you're not just getting the problem from there.
Then, in your onCreate() method, do:

code1:

getWindow().setFormat(PixelFormat.RGBA_8888); getWindow().addFlags(WindowManager.LayoutParams.FLAG_DITHER);

And to load your image explicitly as a 32-bit image (RGBA-8888 configuration) add the following where you load your views:

code2:

BitmapFactory.Options options = new BitmapFactory.Options(); options.inPreferredConfig = Bitmap.Config.ARGB_8888; Bitmap gradient = BitmapFactory.decodeResource(getResources(), R.drawable.gradient, options); findViewById(R.id.main).setBackgroundDrawable(new BitmapDrawable(gradient));


Comparison between different approaches:(these are all screenshots from the resulting application)

My source images (64 colors to the left, 24 bit to the right):
image1 and image2:

1: Raw 64-color image (image1) set as background from layout XML:

2: The same image (image1), using code1:

3: The same image (image1) using both code1 and code2:

4: image2, loaded with code1 and code2 (in this case the dithering is not really important as both the source and destination use 8 bits per color):

更多相关文章

  1. 代码中设置drawableleft
  2. android 3.0 隐藏 系统标题栏
  3. Android开发中activity切换动画的实现
  4. Android(安卓)学习 笔记_05. 文件下载
  5. Android中直播视频技术探究之—摄像头Camera视频源数据采集解析
  6. 技术博客汇总
  7. android 2.3 wifi (一)
  8. AndRoid Notification的清空和修改
  9. Android中的Chronometer

随机推荐

  1. Android TextView setMovementMethod 滑
  2. Android中的Logcat方法查看内核的日志
  3. 【JNI】 Android JNI入门实例(Windows+Cyg
  4. android 多线程 AsyncTask handler
  5. Android(安卓)Studio一些偷懒插件
  6. 一个切换的Widget
  7. 【059】分享我的 Android 应用
  8. Android最全UI库合集
  9. android 开发谷歌地图的步骤
  10. Android自定义View模拟并实现3D柱状图