Android get picture actual size compatible Tablet PC

Source: Internet
Author: User

The project has a picture in the tablet display particularly small reasons, has been struggling to find the reason, there is no tablet computer test, today found a modified resolution, writing related methods finally processed, recorded comparison:
So as not to build the wheel later.
The main is to obtain the relevant picture display problems, directly with the Getintrinsicwidth () method to obtain, Getintrinsicwidth () is not the actual width of the picture, in the mobile phone to see passable, will not be too far, but in the tablet computer to see,
It was a little girl, too shy to show so little.
Back to the chase:
Workaround:
1. Get the phone resolution multiplied by its density
   if (file.exists ()) {            //If the file already exists, return directly to            drawable drawable = Drawable.createfrompath (Savepath);            Displaymetrics  dm = new Displaymetrics ();            Get phone screen resolution            DM = Context.getresources (). Getdisplaymetrics ();             Screen actual size             //  int screenwidth = dm.widthpixels;  int screenheight = dm.heightpixels;             float density = dm.density;             Picture actual size             int imgwidth = (int) (Drawable.getintrinsicwidth () *density);             int imgheight = (int) (Drawable.getintrinsicheight () * density);             Drawable.setbounds (0, 0, drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());              Drawable.setbounds (0, 0, imgwidth,imgheight);            }            return drawable;        }


No picture when loaded

private void Setdrawable (drawable ndrawable) {drawable = ndrawable;            Drawable.setbounds (0, 0, drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());                        SetBounds (0, 0, drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());            Displaymetrics dm = new Displaymetrics ();             Get phone screen resolution DM = Context.getresources (). Getdisplaymetrics ();             screen actual size//int screenwidth = Dm.widthpixels;             int screenheight = Dm.heightpixels;             float density = dm.density;             Picture actual size int imgwidth = (int) (Drawable.getintrinsicwidth () *density);             int imgheight = (int) (Drawable.getintrinsicheight () * density);              Drawable.setbounds (0, 0, drawable.getintrinsicwidth (), Drawable.getintrinsicheight ());              Drawable.setbounds (0, 0, imgwidth,imgheight); SetBounds (0, 0, ImgWidth, imgheight); Note Plus, do not add up the picture and the text is confused together}
Original address: Http://hongshengpeng.com/article/show/254.aspx

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.