简体   繁体   English

Android中的屏幕尺寸和布局

[英]Screen Size and Layout in Android

I'm creating an application in Android Studio, but the application does not work on multiple screen sizes. 我正在Android Studio中创建一个应用程序,但该应用程序无法在多种屏幕尺寸上使用。 I've seen on the internet, people using different xml files with the same name (just change the "setting" it, how large and etc). 我在互联网上看到,人们使用具有相同名称的不同xml文件(只需更改它的“设置”,大小等等)。 The best way to do the layout of my application is to use different xml for each screen size? 进行应用程序布局的最佳方法是为每个屏幕尺寸使用不同的xml? Or does it have an easier way to create an xml and use this for the various screen sizes? 还是有更简单的方法来创建xml并将其用于各种屏幕尺寸?

And to complete, I'm using the relative layout, but on the internet, people say that to use LinearLayout , which is better? 最后,我正在使用相对布局,但是在互联网上,人们说要使用LinearLayout ,哪个更好?

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. 我正在Visual Studio中创建一个应用程序,但该应用程序无法在多种屏幕尺寸上使用。 I've seen on the internet, people using different xml files with the same name (just change the "setting" it, how large and etc). 我在互联网上看到,人们使用具有相同名称的不同xml文件(只需更改它的“设置”,大小等等)。 The best way to do the layout of my application is to use different xml for each screen size? 进行应用程序布局的最佳方法是为每个屏幕尺寸使用不同的xml? Or does it have an easier way to create an xml and use this for the various screen sizes? 还是有更简单的方法来创建xml并将其用于各种屏幕尺寸?

Yes. 是。 If you want to support a different layout for a larger / smaller screen size, you have to provide a diffrent xml file. 如果要为更大/较小的屏幕尺寸支持不同的布局,则必须提供一个不同的xml文件。 You can do this by creating a layout folder. 您可以通过创建布局文件夹来做到这一点。 https://developer.android.com/training/multiscreen/screensizes 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. 例如,LinearLayout对于组件垂直或水平排列的简单布局非常有用。 If your layout is more complex, a RelativeLayout would be better to use BUT... 如果您的布局更复杂,则最好使用RelativeLayout来...

I would recommend you to use ConstraintLayout instead of a RelativeLayout. 我建议您使用ConstraintLayout而不是RelativeLayout。 The two layouts position items relative to other components but ConstraintsLayout is way more powerful that RelativeLayout. 这两个布局相对于其他组件定位项目,但是ConstraintsLayout比RelativeLayout更强大。 You should take a look at it. 您应该看看它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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