0

Is it possible to set different height while creating bitmap based on device. I mean to say that for phones i want to set different height to the bitmap & for tablets i want to set different height. Right now the height and width of the bitmap is declared in dimen.xml file & i am using same height for all devices(Phone & tablets).

But my requirement is to set different bitmap height when showing in tablets. So how that can be done.

code used to create bitmap

Bitmap canvasBitmap = Bitmap.createBitmap(getResources().getDimension(R.dimen.width), getResources().getDimension(R.dimen.height), Bitmap.Config.ARGB_8888);
Rahul
  • 1,667
  • 6
  • 21
  • 38
  • 1
    You can read the screen size of device programmatically and specify width and height value accordingly, while creating bitmap. –  Aug 27 '13 at 07:26
  • Is there any way to create dimen.xml file for different device, just like creating layout-normal, layout-large, layout-xlarge. – Rahul Aug 27 '13 at 07:28
  • Yes, you can make different values folder as with layouts. values-land, values-normal, ... – Juangcg Aug 27 '13 at 07:31

1 Answers1

0

Some example i use in fragment it can give you some idea:

getActivity().getWindowManager().getDefaultDisplay().getMetrics(this._metrics);

        final int _lowDensityWidth = 55;
        final int _lowDensityHeight = 55;
        final int _medDensityWidth = 85;
        final int _medDensityHeight = 85;
        final int _higDensityWidth = 155;
        final int _higDensityHeight = 155;
        switch (_metrics.densityDpi) {
            case DisplayMetrics.DENSITY_LOW:
                imageView.setLayoutParams(new GridView.LayoutParams(_lowDensityWidth, _lowDensityHeight));
                break;
            case DisplayMetrics.DENSITY_MEDIUM:
                imageView.setLayoutParams(new GridView.LayoutParams(_medDensityWidth, _medDensityHeight));
                break;
            case DisplayMetrics.DENSITY_HIGH:
                imageView.setLayoutParams(new GridView.LayoutParams(_higDensityWidth, _higDensityHeight));
                break;
        }
An-droid
  • 6,433
  • 9
  • 48
  • 93