简体   繁体   中英

How to auto adjust the views in Android Studio 3.0 according to the screen size of the device

enter image description here I am unable to implement the auto-layout concept in Android Studio as i used to do in in Xcode.

Here are the screenshots, one is on Nexus One screen and another one is on Nexus 7's big screen. View aren't getting adjusted automatically according to the screen size.

I haven't seen your code but there are a few things you can try:

  • Use different drawables for different screen densities ( drawables-hdpi , drawables-xhdpi and so on).
  • In your .xml file when defining your sizes use dp instead of px . dp or display pixels will fill the screen according to how many pixels there are rather than assuming there are the same amount of pixels on each screen.
  • Use Margins instead of absolute sizes. (eg android:layout_marginLeft="2dp" ) would mean that that item lets say a button will be 2 display pixels from the left margin of the phone.

  • The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

     
    粤ICP备18138465号  © 2020-2024 STACKOOM.COM