Android image on tablets and phones

后端 未结 1 1975
慢半拍i
慢半拍i 2020-12-12 06:50

I have problem,l make application and l want images take same part of screen(10inch tablet and 5inch phone).For example l want image take half width on tablet and on phone..

相关标签:
1条回答
  • 2020-12-12 07:41

    My standard size images are 320 by 200 (for phones) and I store them in the mdpi directory. For tablets I resize them to 480 by 300 like this:

            if (isTablet(getActivity())){  // tablets only
               debugLog( "display tablet image="+imagename);
               int resID = getResources().getIdentifier(imagename,"drawable", getActivity().getPackageName());                       // the corresponding resource id
               if (resID != 0) {
                  Bitmap bmp=BitmapFactory.decodeResource(getResources(), resID);
                  int width=480;
                  int height=300;
                  Bitmap resizedbitmap=Bitmap.createScaledBitmap(bmp, width, height, true);
                  ImageView imageView = (ImageView) getActivity().findViewById(R.id.tablet_image);  // the imageview to change
                  //imageView.setImageResource(resID);
                  imageView.setImageBitmap(resizedbitmap);
               }
            }
    

    I do it this way because I have many images and I do not want to store and maintain two copies of each.

    0 讨论(0)
提交回复
热议问题