How to fit your Android screen

Source: Internet
Author: User
<span id="Label3"></p><pre><pre><span style="color: #000000;"><br></span><span style="color: #0000ff;">New</span> <span style="color: #000000;">displaymetrics (); Getwindowmanager (). getdefaultdisplay (). getmetrics (metric); </span> <span style="color: #0000ff;">int</span> width =<span style="color: #000000;"> metric.widthpixels; </span> <span style="color: #0000ff;">int</span> height =<span style="color: #000000;"> metric.heightpixels;</span> <span style="color: #0000ff;"> float</span> density =<span style="color: #000000;"> metric.density; </span> = metric.densitydpi;</pre></pre><p><p>After knowing the dengsitydpi, there is an adaptation setting using the width and height of the layout for different phone sizes.</p></p><p><p>For example, the size of the image I want to add is 100dp. You can set this up as Follows:</p></p><pre><pre><span style="color: #0000ff;">Final</span> <span style="color: #0000ff;">New</span> <span style="color: #000000;">ImageView (view.getcontext ()); </span> <span style="color: #0000ff;">double</span> size = densitydpi/160.0*100.0<span style="color: #000000;">; </span> <span style="color: #0000ff;">New</span> Viewgroup.layoutparams ((<span style="color: #0000ff;">int</span><span style="color: #000000;">) size, (</span><span style="color: #0000ff;">int</span><span style="color: #000000;">) size); Image.setlayoutparams (img);</span></pre></pre><p><p>Note: layoutparams (int, Int) The parameter units to be set on this side are pixel!</p></p><p><p></p></p><p><p>How to fit your Android screen</p></p></span>

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.