Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.image); BitmapDrawable bitmapDrawable = new BitmapDrawable(bmp); bitmapDrawable.setGravity(Gravity.BOTTOM|Gravity.RIGHT); LinearLayout layout = (LinearLayout) findViewById(R.id.background_root); layout.setBackgroundDrawable(bitmapDrawable);
private void updateBitmapForTextView(TextView view, Bitmap bitmap) { Drawable faviconDrawable = null; if (bitmap != null) { faviconDrawable = new BitmapDrawable(mContext.getResources(), bitmap); ((BitmapDrawable) faviconDrawable).setGravity(Gravity.FILL); } else { faviconDrawable = new ColorDrawable(Color.TRANSPARENT); } faviconDrawable.setBounds(0, 0, mFaviconSize, mFaviconSize); view.setCompoundDrawables(faviconDrawable, null, null, null); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_layer_list_main); LayerDrawable drw = createHorizontallyStackedImages(); ImageView iv1 = (ImageView)findViewById(R.id.imageView1); iv1.setImageDrawable(drw); } private LayerDrawable createHorizontallyStackedImages(){ BitmapDrawable d1 = (BitmapDrawable) getResources().getDrawable(R.drawable.abcgo_48_48_2x); d1.setGravity(Gravity.LEFT); BitmapDrawable d2 = (BitmapDrawable) getResources().getDrawable(R.drawable.amazon_48x48_2x); d2.setGravity(Gravity.LEFT); //BitmapDrawable d3 = (BitmapDrawable) getResources().getDrawable(R.drawable.hulu_48x48_2x); //d3.setGravity(Gravity.LEFT); Drawable drawableArray[]= new Drawable[]{d1,d2}; LayerDrawable layerDraw = new LayerDrawable(drawableArray); layerDraw.setLayerInset(0, 0, 0, 52, 0); layerDraw.setLayerInset(1,52,0,52,0); return layerDraw; }
Button button = new Button(getContext()); Bitmap backgroundBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.my_button); BitmapDrawable backgroundDrawable = new BitmapDrawable(getResources(), backgroundBitmap); backgroundDrawable.setGravity(Gravity.CENTER); // also LEFT, CENTER_VERTICAL, etc. backgroundDrawable.setColorFilter(new PorterDuffColorFilter(Color.RED, PorterDuff.Mode.SRC_ATOP)); button.setBackground(backgroundDrawable);
private void setTabSwitcherAnimationMenuBadgeDrawable() { mTabSwitcherAnimationMenuBadgeDarkDrawable = ApiCompatibilityUtils.getDrawable( getResources(), R.drawable.badge_update_dark); mTabSwitcherAnimationMenuBadgeDarkDrawable.mutate(); ((BitmapDrawable) mTabSwitcherAnimationMenuBadgeDarkDrawable).setGravity(Gravity.CENTER); mTabSwitcherAnimationMenuBadgeLightDrawable = ApiCompatibilityUtils.getDrawable( getResources(), R.drawable.badge_update_light); mTabSwitcherAnimationMenuBadgeLightDrawable.mutate(); ((BitmapDrawable) mTabSwitcherAnimationMenuBadgeLightDrawable).setGravity(Gravity.CENTER); }
Drawable[] layers = new Drawable[this.itemCount]; Resources resources = getResources(); ImageButton imgButton = (ImageButton) findViewById(R.id.btnItems); DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); for (int i = 0; i < this.itemCount; i++) { Bitmap bm = BitmapFactory.decodeResource(resources, R.drawable.icon); BitmapDrawable bmd = new BitmapDrawable(bm); bmd.setGravity(Gravity.TOP); bmd.setTargetDensity(metrics); layers[i] = bmd; } LayerDrawable layerDrawable = new LayerDrawable(layers); int layerTop = 0; for (int i = 0; i < this.itemCount; i++) { int layerLeft = i % 2 == 1 ? 5 : 0; layerDrawable.setLayerInset(i, layerLeft, layerTop, -layerLeft, -layerTop); layerTop += i % 2 == 1 ? 10 : 0; } imgButton.setImageDrawable(layerDrawable);
BitmapDrawable tile = (BitmapDrawable) res.getDrawable(R.drawable.background); tile.setTileModeX(Shader.TileMode.REPEAT); tile.setGravity(Gravity.bottom) tile.setTileModeY(Shader.TileMode.CLAMP); // it replicates the edge color if the shader draws outside of its original bounds //thus you don't even need to set a background color. view.setBackgroundDrawable(tile);
private class ImageGetter implements Html.ImageGetter { public Drawable getDrawable(String source) { BitmapDrawable d = getPicture(source); d.setBounds(new Rect(0,0,d.getIntrinsicWidth(),d.getIntrinsicHeight()+5)); d.setGravity(Gravity.TOP); return d; } };
LinearLayout layout = (LinearLayout) findViewById(R.id.testreportlinearlayout); Bitmap bmp = imgLoader.getBitmap(iconUrl); Bitmap blurredBmp = CommonUtils.blurBitmap(bmp, Constants.RADIUS); Bitmap scaledBmp = Bitmap.createScaledBitmap(blurredBmp, MAX_OF_NEW_XY, MAX_OF_NEW_XY, false); BitmapDrawable scaledBmpdrawable = new BitmapDrawable(getResources(), scaledBmp); scaledBmpdrawable.setAlpha(Constants.ALPHA); scaledBmpdrawable.setGravity(Gravity.CENTER); if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) { layout.setBackgroundDrawable(scaledBmpdrawable); } else { layout.setBackground(scaledBmpdrawable); }
? R.drawable.checkmark_white : R.drawable.checkmark_black); checkmark.setGravity(Gravity.CENTER); drawable = new LayerDrawable(new Drawable[]{ colorChoiceDrawable,
public Drawable getDrawable(String source) { BitmapDrawable d = ...; d.setBounds(new Rect(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight() + 5)); d.setGravity(Gravity.TOP); return d; }
private void setTabSwitcherAnimationMenuDrawable() { if (!shouldShowMenuButton()) return; mTabSwitcherAnimationMenuDrawable = ApiCompatibilityUtils.getDrawable(getResources(), R.drawable.btn_menu); mTabSwitcherAnimationMenuDrawable.mutate(); mTabSwitcherAnimationMenuDrawable.setColorFilter( isIncognito() ? mLightModeDefaultColor : mDarkModeDefaultColor, PorterDuff.Mode.SRC_IN); ((BitmapDrawable) mTabSwitcherAnimationMenuDrawable).setGravity(Gravity.CENTER); }
@SuppressLint("RtlHardcoded") private Drawable getIllustration(Drawable asset, Drawable horizontalTile) { final Context context = getContext(); if (context.getResources().getBoolean(R.bool.suwUseTabletLayout)) { // If it is a "tablet" (sw600dp), create a LayerDrawable with the horizontal tile. if (horizontalTile instanceof BitmapDrawable) { ((BitmapDrawable) horizontalTile).setTileModeX(TileMode.REPEAT); ((BitmapDrawable) horizontalTile).setGravity(Gravity.TOP); } if (asset instanceof BitmapDrawable) { // Always specify TOP | LEFT, Illustration will flip the entire LayerDrawable. ((BitmapDrawable) asset).setGravity(Gravity.TOP | Gravity.LEFT); } final LayerDrawable layers = new LayerDrawable(new Drawable[] { horizontalTile, asset }); if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { layers.setAutoMirrored(true); } return layers; } else { // If it is a "phone" (not sw600dp), simply return the illustration if (VERSION.SDK_INT >= VERSION_CODES.KITKAT) { asset.setAutoMirrored(true); } return asset; } }
public Drawable createBackground(Bitmap bitmap) { Drawable[] layers = new Drawable[3]; BitmapDrawable bitmapDrawable = new BitmapDrawable(bitmap); bitmapDrawable.setGravity(Gravity.BOTTOM | Gravity.RIGHT); layers[0] = bitmapDrawable; GradientDrawable gd = new GradientDrawable(); gd.setShape(GradientDrawable.RECTANGLE); gd.setGradientRadius(500); gd.setGradientType(GradientDrawable.RADIAL_GRADIENT); gd.setColors(new int[] { Color.parseColor("#17568A"), Color.parseColor("#494C4F") }); layers[1] = gd; BitmapDrawable lastBitmapDrawable = (BitmapDrawable) getResources() .getDrawable(R.id.gradient_dish); lastBitmapDrawable.setTileModeX(TileMode.REPEAT); layers[2] = lastBitmapDrawable; LayerDrawable bck = new LayerDrawable(layers); return bck; }
bd.setGravity(Gravity.TOP | Gravity.LEFT); drawables[i * colCount + j] = bd;