在LinearLayout中按钮之间除去空间(安卓) [英] Remove space between buttons in LinearLayout (Android)

查看:140
本文介绍了在LinearLayout中按钮之间除去空间(安卓)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要让我自己的工具栏在Android应用程序。 现在,它看起来像这样:

I need to make my own toolbar in Android application. Now it looks like this:

所以你看按钮之间的空间。我试图把消极的边距/填充的按钮,但空间并没有消失。

So you see spaces between buttons. I tried to put negative margin/padding at buttons, but space didn't disappear.

下面是布局code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <ListView
        android:id="@+id/routes_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5">
    </ListView>

    <TableRow
        android:id="@+id/toolbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="0dp"
        android:padding="0dp" >

        <Button
            android:id="@+id/btn_routes"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:layout_weight="0.2"
            android:layout_marginRight="-10dp"
            android:layout_marginLeft="-10dp"
            android:text="@string/routes"
            android:textSize="10dp" />

        <Button
            android:id="@+id/btn_places"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:layout_weight="0.2"
            android:layout_marginRight="-10dp"
            android:layout_marginLeft="-10dp"
            android:textSize="10dp"
            android:text="@string/places" />

        <Button
            android:id="@+id/btn_events"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:layout_weight="0.2"
            android:layout_marginRight="-10dp"
            android:layout_marginLeft="-10dp"
            android:textSize="10dp"
            android:text="@string/events" />

        <Button
            android:id="@+id/btn_about"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_margin="0dp"
            android:layout_weight="0.2"
            android:layout_marginRight="-10dp"
            android:layout_marginLeft="-10dp"
            android:text="@string/about"
            android:textSize="10dp" />

    </TableRow>

</LinearLayout>

如何按钮之间消除空间?

How to remove space between buttons?

推荐答案

下面是一个解决方案。看来,我急忙张贴的问题在这里。

Here's a solution. It seems that I hurried to post a question here.

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

    <ListView
        android:id="@+id/routes_list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.5">
    </ListView>

    <TableRow
        android:id="@+id/toolbar"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_marginBottom= "-7dp">

        <Button
            android:id="@+id/btn_routes"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:layout_marginRight="-4.5dp"
            android:layout_marginLeft="-5dp"
            android:text="@string/routes"
            android:textSize="10dp" />

        <Button
            android:id="@+id/btn_places"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:layout_marginRight="-4.5dp"
            android:layout_marginLeft="-4.5dp"
            android:textSize="10dp"
            android:text="@string/places" />

        <Button
            android:id="@+id/btn_events"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:layout_marginRight="-4.5dp"
            android:layout_marginLeft="-4.5dp"
            android:textSize="10dp"
            android:text="@string/events" />

        <Button
            android:id="@+id/btn_about"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.2"
            android:layout_marginRight="-4dp"
            android:layout_marginLeft="-4.5dp"
            android:text="@string/about"
            android:textSize="10dp" />

    </TableRow>

</LinearLayout>

结果:

Result:

这篇关于在LinearLayout中按钮之间除去空间(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆