Android 布局 - 设置图像按钮之间的间距
我在栏顶部有四个按钮(背景图像)。我想做的是增加按钮之间的间距(这样它们就分布在横条上)并将重力设置为 center_horozontal 。我在 ImageButtons (okcancelbar_button_home) 本身上尝试了 paddingLeft 和 paddingRight ,但它似乎没有做任何事情。我想也许图像按钮父项是关键,但我不知道在那里设置什么。这是我的布局:
///////// main .xml //////////////////
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<com.onesix.test.OkCancelBar
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_gravity="top"
android:paddingTop="0dip"
android:gravity="center_horizontal"
android:background="@drawable/header_bkgrnd"
/>
<!--"#AA000000"-->
</merge>
////////// okCancelBar ////////////////
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<include
layout="@layout/okcancelbar_button_home"
android:id="@+id/okcancelbar_home"
android:layout_height="90dip" />
<include
layout="@layout/okcancelbar_button_lists"
android:id="@+id/okcancelbar_lists"
android:layout_height="90dip"
/>
<include
layout="@layout/okcancelbar_button_calendar"
android:id="@+id/okcancelbar_calendar"
android:layout_height="90dip"
/>
<include
layout="@layout/okcancelbar_button_search"
android:id="@+id/okcancelbar_search"
android:layout_height="90dip"
/>
</merge>
////////////// okcancelbar_button_home ////////////////
<?xml version="1.0" encoding="utf-8"?>
<ImageButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/but_home"
android:layout_width="75dip"
android:layout_height="60dip"
android:layout_alignParentBottom="true"
android:background="@android:color/transparent"
android:src="@drawable/button_menu_states_home"
android:paddingLeft="7dip"
android:paddingRight="7dip"
/>
////////////button_menu_states_home/////////
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/menu_button_home1_over" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/menu_button_home1_over" /> <!-- focused -->
<item android:drawable="@drawable/menu_button_home1" /> <!-- default -->
</selector>
I have four buttons on top of a bar (background image) . What I'm trying to do is increase the spacing between the buttons (so they are spread out across the bar) and set the gravity to center_horozontal . I tries paddingLeft and paddingRight on ImageButtons (okcancelbar_button_home) themselves but it doesn't seem to do anything. I'm thinking maybe the Image Buttons parent is the key but I don't know what to set there. Here is my layout :
///////// main .xml //////////////////
<merge
xmlns:android="http://schemas.android.com/apk/res/android">
<com.onesix.test.OkCancelBar
android:layout_width="fill_parent"
android:layout_height="60dip"
android:layout_gravity="top"
android:paddingTop="0dip"
android:gravity="center_horizontal"
android:background="@drawable/header_bkgrnd"
/>
<!--"#AA000000"-->
</merge>
////////// okCancelBar ////////////////
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<include
layout="@layout/okcancelbar_button_home"
android:id="@+id/okcancelbar_home"
android:layout_height="90dip" />
<include
layout="@layout/okcancelbar_button_lists"
android:id="@+id/okcancelbar_lists"
android:layout_height="90dip"
/>
<include
layout="@layout/okcancelbar_button_calendar"
android:id="@+id/okcancelbar_calendar"
android:layout_height="90dip"
/>
<include
layout="@layout/okcancelbar_button_search"
android:id="@+id/okcancelbar_search"
android:layout_height="90dip"
/>
</merge>
////////////// okcancelbar_button_home ////////////////
<?xml version="1.0" encoding="utf-8"?>
<ImageButton
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/but_home"
android:layout_width="75dip"
android:layout_height="60dip"
android:layout_alignParentBottom="true"
android:background="@android:color/transparent"
android:src="@drawable/button_menu_states_home"
android:paddingLeft="7dip"
android:paddingRight="7dip"
/>
////////////button_menu_states_home/////////
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/menu_button_home1_over" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/menu_button_home1_over" /> <!-- focused -->
<item android:drawable="@drawable/menu_button_home1" /> <!-- default -->
</selector>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更改按钮上的填充会增加实际按钮的大小。您可以将其视为更改按钮文本的填充,而不是按钮本身。
要更改按钮之间的间距,您可以使用
layout_margin
属性(例如android:layout_marginLeft
=...)。Changing the padding on a button will increase the size of the actual button. You can think of it as changing the padding for the button's text, not the button itself.
To change the spacing between the buttons you can use the
layout_margin
attributes (e.g.android:layout_marginLeft
=...).