确保两个相互替换的线性布局具有相同的大小
我有一个应用程序的顶部部分,主要是徽标和其他内容,大约下半部分应该是按钮。在外部容器中,我有一个徽标布局,以及用于在顶部之间创建分隔线的 imageView和底部和底部布局..
问题是底部布局有2个线性布局(其中一个最初是隐藏的)第一个只是一个旋转器,第二个是2个按钮..
我已经实现了“大约1/3的空间” )通过使用layout_weights在顶部和底部线性布局中(分别为 2 和 1),但是当我隐藏微调器并在代码中的底部布局中显示 2 个按钮时,分隔线被推上。我希望它保持在同一位置(就像从一开始就出现 2 个按钮后的位置,这样它就不必移动)
我可能只需在原始按钮上添加一些边距以匹配它,但我觉得这会导致问题未来在不同的设备上
我该如何实现这一点 。壮举?
I have a top section for the app which is mainly logo and stuff, and roughly the bottom half is supposed to be buttons.. In the outer container, i have a layout for the logo, and imageView to create a seperator line between the top and bottom and the bottom layout..
The issue is bottom layout has 2 linearlayouts (one of which is hidden initially) first one is just a spinner and the second one is 2 buttons..
I have achieved the "roughly 1/3 of space) by using layout_weights in the top and bottom linear layout (2 and 1 respectively) but when I hide the spinner and show the 2 buttons in the bottom layout in the code, the seperator line is pushed up.. I want it to stay in the same place (like be where it would be after the 2 buttons show up from the get-go so that it doesn't have to move)
I could probably just add some margin to the original one to match it but i feel like that will cause issues in the future on different devices.
How can I accomplish this feat?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能忽略了在设置
android:layout_weight="1"
的 LinearLayouts 上设置android:layout_height="0dp"
。如果您这样做,它应该像您想要的那样填充空间,您可以执行layoutView.setVisibility(View.GONE)
和layoutView.setVisibility(View.VISIBLE)
来切换的意见。I think you might be neglecting to set
android:layout_height="0dp"
on the LinearLayouts that you setandroid:layout_weight="1"
on. If you do this it should fill the space like you want, and you can dolayoutView.setVisibility(View.GONE)
andlayoutView.setVisibility(View.VISIBLE)
to toggle the views.