final LayoutInflater li = (LayoutInflater)getSystemService( LAYOUT_INFLATER_SERVICE); this.setTitle(R.string.density_title); LinearLayout root = new LinearLayout(this); root.setOrientation(LinearLayout.VERTICAL); addBitmapDrawable(layout, R.drawable.logo120dpi, true); addBitmapDrawable(layout, R.drawable.logo160dpi, true); addBitmapDrawable(layout, R.drawable.logo240dpi, true); addLabelToRoot(root, "Prescaled bitmap in drawable"); addChildToRoot(root, layout); addBitmapDrawable(layout, R.drawable.logo120dpi, false); addBitmapDrawable(layout, R.drawable.logo160dpi, false); addBitmapDrawable(layout, R.drawable.logo240dpi, false); addLabelToRoot(root, "Autoscaled bitmap in drawable"); addChildToRoot(root, layout); addResourceDrawable(layout, R.drawable.logo120dpi); addResourceDrawable(layout, R.drawable.logo160dpi); addResourceDrawable(layout, R.drawable.logo240dpi); addLabelToRoot(root, "Prescaled resource drawable"); addChildToRoot(root, layout); addLabelToRoot(root, "Inflated layout"); addChildToRoot(root, layout); addLabelToRoot(root, "Inflated styled layout");
private Bitmap loadAndPrintDpi(int id, boolean scale) { Bitmap bitmap; if (scale) { bitmap = BitmapFactory.decodeResource(getResources(), id); } else { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inScaled = false; bitmap = BitmapFactory.decodeResource(getResources(), id, opts); } return bitmap; }
private void addBitmapDrawable(LinearLayout layout, int resource, boolean scale) { Bitmap bitmap; bitmap = loadAndPrintDpi(resource, scale); View view = new View(this); final BitmapDrawable d = new BitmapDrawable(getResources(), bitmap); if (!scale) d.setTargetDensity(getResources().getDisplayMetrics()); view.setBackgroundDrawable(d); view.setLayoutParams(new LinearLayout.LayoutParams(d.getIntrinsicWidth(), d.getIntrinsicHeight())); layout.addView(view); }
private void addCanvasBitmap(LinearLayout layout, int resource, boolean scale) { Bitmap bitmap; bitmap = loadAndPrintDpi(resource, scale); ScaledBitmapView view = new ScaledBitmapView(this, bitmap); view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.addView(view); }
private void addBitmapDrawable(LinearLayout layout, int resource, boolean scale) { Bitmap bitmap; bitmap = loadAndPrintDpi(resource, scale); View view = new View(this); final BitmapDrawable d = new BitmapDrawable(getResources(), bitmap); if (!scale) d.setTargetDensity(getResources().getDisplayMetrics()); view.setBackgroundDrawable(d); view.setLayoutParams(new LinearLayout.LayoutParams(d.getIntrinsicWidth(), d.getIntrinsicHeight())); layout.addView(view); }
private void addCanvasBitmap(LinearLayout layout, int resource, boolean scale) { Bitmap bitmap; bitmap = loadAndPrintDpi(resource, scale); ScaledBitmapView view = new ScaledBitmapView(this, bitmap); view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT)); layout.addView(view); }
final LayoutInflater li = (LayoutInflater)getSystemService( LAYOUT_INFLATER_SERVICE); this.setTitle(R.string.density_title); LinearLayout root = new LinearLayout(this); root.setOrientation(LinearLayout.VERTICAL); addBitmapDrawable(layout, R.drawable.logo120dpi, true); addBitmapDrawable(layout, R.drawable.logo160dpi, true); addBitmapDrawable(layout, R.drawable.logo240dpi, true); addLabelToRoot(root, "Prescaled bitmap in drawable"); addChildToRoot(root, layout); addBitmapDrawable(layout, R.drawable.logo120dpi, false); addBitmapDrawable(layout, R.drawable.logo160dpi, false); addBitmapDrawable(layout, R.drawable.logo240dpi, false); addLabelToRoot(root, "Autoscaled bitmap in drawable"); addChildToRoot(root, layout); addResourceDrawable(layout, R.drawable.logo120dpi); addResourceDrawable(layout, R.drawable.logo160dpi); addResourceDrawable(layout, R.drawable.logo240dpi); addLabelToRoot(root, "Prescaled resource drawable"); addChildToRoot(root, layout); addLabelToRoot(root, "Inflated layout"); addChildToRoot(root, layout); addLabelToRoot(root, "Inflated styled layout");
private Bitmap loadAndPrintDpi(int id, boolean scale) { Bitmap bitmap; if (scale) { bitmap = BitmapFactory.decodeResource(getResources(), id); } else { BitmapFactory.Options opts = new BitmapFactory.Options(); opts.inScaled = false; bitmap = BitmapFactory.decodeResource(getResources(), id, opts); } return bitmap; }
private void addResourceDrawable(LinearLayout layout, int resource) { View view = new View(this); final Drawable d = getResources().getDrawable(resource); view.setBackgroundDrawable(d); view.setLayoutParams(new LinearLayout.LayoutParams(d.getIntrinsicWidth(), d.getIntrinsicHeight())); layout.addView(view); }
private void addNinePatchResourceDrawable(LinearLayout layout, int resource) { View view = new View(this); final Drawable d = getResources().getDrawable(resource); view.setBackgroundDrawable(d); Log.i("foo", "9-patch #" + Integer.toHexString(resource) + " w=" + d.getIntrinsicWidth() + " h=" + d.getIntrinsicHeight()); view.setLayoutParams(new LinearLayout.LayoutParams( d.getIntrinsicWidth()*2, d.getIntrinsicHeight()*2)); layout.addView(view); }
private void addResourceDrawable(LinearLayout layout, int resource) { View view = new View(this); final Drawable d = getResources().getDrawable(resource); view.setBackgroundDrawable(d); view.setLayoutParams(new LinearLayout.LayoutParams(d.getIntrinsicWidth(), d.getIntrinsicHeight())); layout.addView(view); }
private void addNinePatchResourceDrawable(LinearLayout layout, int resource) { View view = new View(this); final Drawable d = getResources().getDrawable(resource); view.setBackgroundDrawable(d); Log.i("foo", "9-patch #" + Integer.toHexString(resource) + " w=" + d.getIntrinsicWidth() + " h=" + d.getIntrinsicHeight()); view.setLayoutParams(new LinearLayout.LayoutParams( d.getIntrinsicWidth()*2, d.getIntrinsicHeight()*2)); layout.addView(view); }