我已经看过很多关于此的帖子,并尝试了许多解决方案,但由于某些原因,没有任何工作。我只是希望按钮共享相同的空间...你能看看我的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>
编辑:这似乎与设置背景有关,我删除了背景,除了你还必须滚动之外,所有内容都是相等的空间。
答案 0 :(得分:2)
尝试删除android:weightSum="120"
并在所有按钮上将android:layout_weight="20"
设置为android:layout_weight="1"
。
答案 1 :(得分:1)
您的LinearLayout具有垂直方向,因此您应使用android:layout_width="0dp"
代替android:layout_height="0dp"
。