简体   繁体   中英

Screen Size and Layout in Android

I'm creating an application in Android Studio, but the application does not work on multiple screen sizes. I've seen on the internet, people using different xml files with the same name (just change the "setting" it, how large and etc). The best way to do the layout of my application is to use different xml for each screen size? Or does it have an easier way to create an xml and use this for the various screen sizes?

And to complete, I'm using the relative layout, but on the internet, people say that to use LinearLayout , which is better?

Thank you for your help and sorry for my english!

I'm creating an application in Visual Studio, but the application does not work on multiple screen sizes. I've seen on the internet, people using different xml files with the same name (just change the "setting" it, how large and etc). The best way to do the layout of my application is to use different xml for each screen size? Or does it have an easier way to create an xml and use this for the various screen sizes?

Yes. If you want to support a different layout for a larger / smaller screen size, you have to provide a diffrent xml file. You can do this by creating a layout folder. https://developer.android.com/training/multiscreen/screensizes

On the other hand, if you think your project can reuse other layouts of your app and jam them together if the screen is larger, you probably use fragments for these kinds of situations.

And to complete, I'm using the relative layout, but on the internet, people say that to use linear layout, which is better?

The type of layout you use depends on your use-case. LinearLayout for example is very useful for a simple layout with components arrange vertically or horizontally. If your layout is more complex, a RelativeLayout would be better to use BUT...

I would recommend you to use ConstraintLayout instead of a RelativeLayout. The two layouts position items relative to other components but ConstraintsLayout is way more powerful that RelativeLayout. You should take a look at it.

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