ANDROID:加权线性列表按钮消失
我看过很多关于此问题的帖子,并尝试了很多解决方案,但由于某种原因没有任何效果。我只是想让按钮共享相同的空间...您能看一下我的 xml 代码并看看是否有问题吗?谢谢!
<ScrollView android:id="@+id/scrollview1"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:weightSum="120">
<Button android:id="@+id/btn_mission" android:layout_width="0dp"
android:layout_height="wrap_content" android:background="#8D8BB7"
android:layout_weight="20" android:text="Mission">
</Button>
<Button android:id="@+id/btn_news" android:layout_width="0dp"
android:layout_height="wrap_content" android:background="#8D8BB7"
android:layout_weight="20" android:text="News/Events">
</Button>
<Button android:id="@+id/btn_studentservices"
android:layout_width="0dp" android:layout_height="wrap_content"
android:background="#8D8BB7" android:layout_weight="20"
android:text="Student Services">
</Button>
<Button android:id="@+id/btn_facultyservices"
android:layout_width="0dp" android:layout_height="wrap_content"
android:background="#8D8BB7" android:layout_weight="20"
android:text="Faculty Services">
</Button>
<Button android:id="@+id/btn_staff" android:layout_width="0dp"
android:layout_height="wrap_content" android:background="#8D8BB7"
android:layout_weight="20" android:text="Staff">
</Button>
<Button android:id="@+id/btn_library" android:layout_width="0dp"
android:layout_height="wrap_content" android:background="#8D8BB7"
android:layout_weight="20" android:text="Library">
</Button>
</LinearLayout>
</ScrollView>
</LinearLayout>
编辑:这似乎与设置背景有关,我删除了背景,并且所有内容共享相等的空间,除了您仍然必须滚动。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试删除
android:weightSum="120"
并将android:layout_weight="20"
设置为android:layout_weight="1"
的按钮。Try removing
android:weightSum="120"
and setting theandroid:layout_weight="20"
toandroid:layout_weight="1"
on all of the buttons.您的 LinearLayout 具有垂直方向,因此您应该使用
android:layout_height="0dp"
而不是android:layout_width="0dp"
。Your LinearLayout has a vertical orientation, so instead of
android:layout_width="0dp"
you should useandroid:layout_height="0dp"
.