Android 图像按钮边距

标签 android image button margin

所以我是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/

相关文章:

android - 是否可以使用蓝牙连接 iOS 和 android 设备?

android - 除非您更新谷歌播放服务,否则应用程序不会运行

java - RxJava的clear(CompositeDisposable)方法内部是如何工作的?

Android:如何将大字体放入小按钮?

html按钮多行对齐

android - 无法从 Shared Preferences Android 检索 boolean 值

reactjs - 如何在ReactJS中制作动态图像?

css - 使用 css 缩小子图像时,IE8 中的容器保留原始图像宽度

java - 检查触摸点是否位于给定区域内

css - 搜索按钮 CSS 上的文本或图像