【问题标题】:ANDROID: Weighted Linear List Buttons disappearANDROID:加权线性列表按钮消失
【发布时间】:2011-06-20 20:15:19
【问题描述】:

我看过很多关于这个的帖子,并尝试了很多解决方案,但由于某种原因,没有任何效果。我只是想让按钮共享相等的空间......你能看看我的 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>

编辑:这似乎与设置背景有关我删除了背景并且所有内容共享相等的空间,除了您仍然必须滚动。

【问题讨论】:

  • I just want the buttons to share equal space... 这是什么意思?横向?垂直?请说明你想要什么。

标签: android xml button android-linearlayout weighted


【解决方案1】:

尝试删除android:weightSum="120" 并将所有按钮上的android:layout_weight="20" 设置为android:layout_weight="1"

【讨论】:

    【解决方案2】:

    您的 LinearLayout 具有垂直方向,因此您应该使用 android:layout_height="0dp" 而不是 android:layout_width="0dp"

    【讨论】:

    • 现在出现了,但是有没有办法让它们现在占用空白空间,它们只是一个接一个地列出来。
    • 为每个按钮尝试 android:layout_width="fill_parent" (我不确定它是否是你想要的)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-09-04
    • 2020-10-11
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    • 2021-07-02
    • 1970-01-01
    相关资源
    最近更新 更多