Android 相对布局 各控件指之间的间距怎么设置

图片说明
就是图片上的四个控件之间都有一些间距,本人新手刚刚开始自学Android,不太熟悉布局,求大神指教
主要布局文件如下:
android:id="@+id/all_music"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/all_music" />

<Button
    android:id="@+id/file"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/file"
    android:layout_marginRight="0dip"
    android:text="@string/file" />
<Button 
    android:id="@+id/singer"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/all_music"
    android:layout_marginBottom="0dip"
    android:text="@string/singer"/>
<Button 
    android:id="@+id/album"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/hot_rank"
    android:layout_toRightOf="@id/singer"
    android:layout_marginBottom="0dip"
    android:layout_marginRight="0dip"
    android:text="@string/album"
    />


请问是我对layout_marginRight 理解错误,还是怎么回事,为什么不能使两个按钮紧靠在一起?

先设置两个控件之间的关系,比如torightof,toleftof,below,above之类的,然后再设置margin,这样就是相对于这两个控件的间距了。

android:layout_marginTop="25dip" //顶部距离
android:layout_marginLeft="15dip" //距离左边距

每个button之间都有一个系统定义好的margin,所以他们是无法靠在一起的,就相当于,它会告诉其他组件,你离我远点,不要靠我靠的太近。。。。。

而且你在xml文件里设置的margin,只能让它们在它们之间能接受的最小距离之间相互靠近而已,并不能完全贴合。

你是想去掉间距? android:layout_marginTop="-20dip",这里的值是可以是负的

Button 自带的背景图片就有一定的边距,加上:
android:background="@android:color/transparent" 去除自带背景图片,边距就没有了。
再重新设置一个背景图片就行了。

在RelativeLayout中设置了一些关键的位置定义以后margin是不管用的,有一个办法可以解决你的问题,你在两个button中间加一个view,给view设置你想要的宽度,然后让两个button分别在这个view的两边就行了
android:id="@+id/singer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/all_music"
android:layout_toLeftOf="@+id/dir"
android:layout_marginBottom="0dip"
android:text="@string/singer"/>
android:id="@+id/dir"
android:layout_width="15dp"
android:layout_height="wrap_content"
/>
android:id="@+id/album"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/hot_rank"
android:layout_toRightOf="@id/dir"
android:layout_marginBottom="0dip"
android:layout_marginRight="0dip"
android:text="@string/album"
/>

试试用线性布局, 这样按钮能埃着

赞一个,现在遇到这个问题,正好帮我解决了