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