问题描述
我目前正在设计一个按钮栏有5个按钮(他们都将ImageButtons,但现在,只有3人是)。这是我的第一个Android项目,所以我学习,我走。我想同样重量每一个按钮,无需缩放他们(有平等的填充而不是平等的宽度)。这是我的code到目前为止:
I am currently designing a ButtonBar with 5 buttons (they will all be ImageButtons, but for now, only 3 of them are). This is my first android project so I'm learning as I go along. I'm trying to weight each button equally, without scaling them (have equal padding rather than equal width). This is my code so far:
<LinearLayout
android:id="@+id/back"
android:orientation="horizontal"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
style="@android:style/ButtonBar"
android:weightSum="5"
>
<ImageButton
android:id="@+id/info_button"
android:padding="20dp"
android:background="@drawable/info"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<Button
android:id="@+id/wishlist_button"
android:text="@string/wish_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:padding="20dp"
android:textSize="15dip"
android:textColor="#b7b7b7"></Button>
<Button
android:id="@+id/buy_button"
android:text="@string/buy_label"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
android:padding="20dp"
android:textSize="15dip"
android:textColor="#b7b7b7"/>
<ImageButton
android:id="@+id/dislike_button"
android:padding="20dp"
android:background="@drawable/dislike_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
<ImageButton
android:id="@+id/like_button"
android:padding="20dp"
android:background="@drawable/like_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_weight="1"
/>
这是它看起来像现在:拉伸加权: http://i.imgur.com/MAfjp.png
This is what it looks like now:stretched weighted: http://i.imgur.com/MAfjp.png
这就是我希望它看起来像(紧密):非拉伸同样填充: http://i.imgur.com/vXTEy.png
This is what I want it to look like (closely):non-stretched equally padded: http://i.imgur.com/vXTEy.png
感谢您的帮助。我一直在寻找了一段时间的答案,并尝试了这么多了。
Thank you for helping. I've been searching for the answer for a while and have tried so much already.
推荐答案
这是:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/back"
android:orientation="horizontal"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:layout_alignParentBottom="true"
android:background="#000000"
style="@android:style/ButtonBar"
android:gravity="center"
>
<ImageButton
android:id="@+id/info_button"
android:background="@null"
android:src="@drawable/info"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
/>
<Button
android:id="@+id/wishlist_button"
android:text="@string/wish_label"
android:background="@null"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textSize="15dip"
android:textColor="#b7b7b7"></Button>
<Button
android:id="@+id/buy_button"
android:text="@string/buy_label"
android:background="@null"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
android:textSize="15dip"
android:textColor="#b7b7b7"/>
<ImageButton
android:id="@+id/dislike_button"
android:background="@null"
android:src="@drawable/dislike_button"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
/>
<ImageButton
android:id="@+id/like_button"
android:background="@null"
android:src="@drawable/like_button"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_weight="1"
/>
</LinearLayout>
我不知道怎么的风格=@安卓风格/按钮栏设置,因此,如果没有正确显示尝试将其删除
I don't know how style="@android:style/ButtonBar" is set, so if it doesn't show properly try remove it.
这篇关于线性布局儿童平等的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!