简体   繁体   English

我应该在Android中使用什么布局类型才能让我的应用适合所有屏幕尺寸?

[英]What layout type should i use in android in order for my app to fit all screen sizes?

I dont want objects in my xml to get cut off from being too big or have the objects too small and unseeable. 我不希望我的xml中的对象被切断太大或者对象太小而且不可见。 Previously i used RelativeLayout but the layout didnt look the same with other screen sizes. 以前我使用RelativeLayout但布局与其他屏幕尺寸看起来不一样。 What can i do to have all layouts fit the screen the same way? 我能做些什么让所有布局都以同样的方式适合屏幕? Thanks! 谢谢!

I suspect your problem arises from the fact that you may be using pixels for your fonts and positioning. 我怀疑你的问题是因为你可能正在使用像素进行字体和定位。

I would recommend using dip or dp instead of px for fonts, that should allow them to scale depending on your device (sort of like em in html). 我建议使用dipdp而不是px作为字体,这应该允许它们根据你的设备进行缩放(有点像html中的em )。 I would also use the same for positioning and sizing on elements. 我也会使用相同的元素来定位和调整大小。

The layouts in android are not so much about what layout to use for what size screens, it is more about which layout you need to use to implement your desired design. android中的布局并不是关于用于什么尺寸屏幕的布局,而是关于您需要使用哪种布局来实现所需设计。 You do not have to stick to one layout for a screen / activity either, each layout can have other layouts embedded in them. 您不必为屏幕/活动坚持一个布局,每个布局都可以嵌入其他布局。

Meaning it's not uncommon to start with a LinearLayout with vertical orientation and then nest under that a LinearLayout with horizontal orientation or even a TableLayout . 这意味着从具有垂直方向的LinearLayout开始,然后在具有水平方向的LinearLayout或甚至TableLayout之下嵌套并不常见。

Similarly you can start with a RelativeLayout and use it to position a LinearLayout somewhere on the screen. 类似地,您可以从RelativeLayout开始,并使用它将LinearLayout定位在屏幕上的某个位置。

you can use RelativeLayout , LinearLayout , FrameLayout and so on. 你可以使用RelativeLayoutLinearLayoutFrameLayout等。 which layout should be used to fit all screen that's a separate thing because we should use layout based on our requirement. 哪个布局应该用于适合所有屏幕,因为我们应该根据我们的要求使用布局。

this site 这个网站

http://developer.android.com/guide/practices/screens_support.html http://developer.android.com/guide/practices/screens_support.html

is really helpful to support multiple screen. 对支持多屏幕非常有帮助。 however you should always put your layout within the scroll view so if the screen is greater than layout , scrolling will not appear but in reverse case it will appear. 但是你应该总是把你的布局放在滚动视图中,所以如果屏幕大于布局,滚动就不会出现,但反过来会出现。

you should consider other paramerts also except layouts. 你应该考虑除布局之外的其他参数。 we use layout based on our requirement. 我们根据我们的要求使用布局。

You can use RelativeLayout so that your every View is place with some relation to other View and try to use match_parent , or you can use weight . 您可以使用RelativeLayout以便您的每个View与其他View有一些关系,并尝试使用match_parent ,或者您可以使用weight If its necessary to fix the size of View and to make it take equal space on all screen resolutions see my answer here 如果需要固定的大小View ,并使其承担所有的屏幕分辨率见我的回答对平等的空间在这里

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

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