List of usage examples for android.graphics.drawable LayerDrawable setDither
@Override public void setDither(boolean dither)
From source file:com.eleybourn.bookcatalogue.utils.Utils.java
/** * Reuse of bitmaps in tiled backgrounds is a known cause of problems: * http://stackoverflow.com/questions/4077487/background-image-not-repeating-in-android-layout * So we avoid reusing them./* w w w . j av a2 s .co m*/ * * This seems to have become further messed up in 4.1 so now, we just created them manually. No references, * but the old cleanup method (see below for cleanupTiledBackground()) no longer works. Since it effectively * un-cached the background, we just create it here. * * The main problem with this approach is that the style is defined in code rather than XML. * * @param a Activity context * @param bright Flag indicating if background should be 'bright' * * @return Background Drawable */ public static Drawable makeTiledBackground(boolean bright) { // Storage for the layers Drawable[] drawables = new Drawable[2]; // Get the BG image, put in tiled drawable Bitmap b = BitmapFactory.decodeResource(BookCatalogueApp.context.getResources(), R.drawable.books_bg); BitmapDrawable bmD = new BitmapDrawable(BookCatalogueApp.context.getResources(), b); bmD.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); // Add to layers drawables[0] = bmD; // Set up the gradient colours based on 'bright' setting int[] colours = new int[3]; if (bright) { colours[0] = Color.argb(224, 0, 0, 0); colours[1] = Color.argb(208, 0, 0, 0); colours[2] = Color.argb(48, 0, 0, 0); } else { colours[0] = Color.argb(255, 0, 0, 0); colours[1] = Color.argb(208, 0, 0, 0); colours[2] = Color.argb(160, 0, 0, 0); } // Create a gradient and add to layers GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colours); drawables[1] = gd; // Make the layers and we are done. LayerDrawable ll = new LayerDrawable(drawables); ll.setDither(true); return ll; }