所以我是android编程的新手,我正在尝试将三个图像按钮一个挨一个地排成一行。
问题是我无法摆脱它们之间的空格,并且我猜添加 *android:layout_marginLeft="0dp"* 和 *android:layout_marginRight="0dp"* 到它们中的每一个都不起作用。我正在使用相对布局。
感谢您的帮助!
这是 XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageButton
android:id="@+id/ib_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="0dp"
android:src="icon2" />
<ImageButton
android:id="@+id/ib_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_toLeftOf="@id/ib_3"
android:src="icon2" />
<ImageButton
android:id="@+id/ib_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ib_2"
android:layout_margin="0dp"
android:src="icon1" />
最佳答案
tru 将图像按钮的背景设置为空。图像按钮有一个默认背景,具体取决于制造商
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageButton
android:id="@+id/ib_3"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="0dp"
android:src="icon2" />
<ImageButton
android:id="@+id/ib_2"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:layout_toLeftOf="@id/ib_3"
android:src="icon2" />
<ImageButton
android:id="@+id/ib_1"
android:background="@null"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@id/ib_2"
android:layout_margin="0dp"
android:src="icon1" />
关于Android 图像按钮边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13315695/