简体   繁体   English

Android布局和屏幕旋转

[英]Android layouts and screen rotation

我今天遇到的另一个问题...我正在寻找与秋千上的flowLayout类似的东西,我一直在寻找却什么也没发现...我需要一些布局,当空间不足时,我要在其中放置3个按钮(在以potrait模式为例)我希望它们像一个按钮一样显示,占据100%的布局空间,而另两个按钮则位于第一个按钮的下方,当有足够的空间时(横向模式),我希望它们以相同的权重放置一条线。我考虑过相对布局,但它缺少重量,另一方面,线性布局不符合我所阅读内容的要求。

What you could try is overriding the onConfigurationChange method of the activity and try implementing some logic there to change the position of the views depending on the orientation of the device. 您可以尝试重写活动的onConfigurationChange方法,然后尝试在其中实现一些逻辑以根据设备的方向更改视图的位置。 Or in your oncreate you could instantiate all your views and hide a complete set of controls for one type of orientation and then on another type do the opposite. 或者,在oncreate中,您可以实例化所有视图并为一种类型的方向隐藏完整的控件集,然后在另一种类型上执行相反的操作。 Ive done both of these and hiding and unhiding the views seemed to be the least performance taxing because everything was instantiated once in oncreate. 我已经完成了所有这些工作,并且隐藏和取消隐藏视图似乎是最少的性能负担,因为在oncreate中实例化了所有实例。 You could also try using seperate layouts all together for each orientation which might decrease performance due to view inflation but if your views are not to complex you might not notice anything except on lesser devices. 您还可以尝试针对每个方向一起使用单独的布局,这可能会由于视图膨胀而降低性能,但是如果视图不复杂,则可能会注意到,除了在较小的设备上之外,您什么都不会注意到。

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

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