2011-11-12 11 views
13

私はちょうどlayout_marginRightlayout_marginLeftを以下のように設定しても、2つのボタンの間のスペースを削除できません。しかし、10 dpのようにスペースを大きく設定すると意味があります。 それを解決する方法はありますか?Android:水平線形の2つのボタンの間にスペースを入れない方法

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:orientation="horizontal" android:padding="0dp" 
    android:layout_height="wrap_content" android:gravity="fill_horizontal" android:layout_margin="0dp"> 
    <Button android:id="@+id/LocationTitleButton" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginRight="0dp" 
        android:layout_gravity="center_vertical" 
        android:layout_weight="1" 
        android:ellipsize="end" 
        android:gravity="center_vertical" 
        android:scrollHorizontally="true" 
        android:singleLine="true" 
        android:text="Add location" 
        android:textStyle="bold" /> 
       <Button android:textColor="#FF000000" 
        android:layout_weight="0" 
        android:id="@+id/AddLocationButton" 
        android:text="Search" 
        android:gravity="center_vertical" 
        android:layout_gravity="center_vertical" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_marginLeft="0dp" /> 
</LinearLayout> 
+1

を埋めるためにあなたは、各ボタンの "0dip" のlayout_widthを設定する必要があります。私はそれが助けて欲しい –

+0

それは機能しません、私は右のボタンがその重量が0であることを消してしまいます。 –

+0

2番目のボタンの重量を0に設定する必要がありますか? –

答えて

38

Bryan's answerをご覧ください。私の答えでは、両方のボタンが重なっています。ブライアンの答えは、ボタンの実際のサイズを示しています。

旧答え:

ちょうど"-8dip"またはそれ以上に最初のボタンのandroid:layout_marginRightを設定します。 2つのボタンの間隔が狭くなるほど小さくなります。

+0

それは本当に扱いにくいですが、うまくいきます! –

+5

負のマージンは避けてください。 – Muzammil

+2

@ムザミル:あなたの意見を説明できますか? –

1

android:layout_marginRight="0dip"を設定する必要があります。もう一方のボタンにはandroid:paddingRight="0dip"のパディングを削除する必要があります。これは左の値に変更する必要があります。私は、すべてのアンドロイド要素にはデフォルトでパディングが追加されていることを忘れていたと思います。これは一般的には良いアイデアですが、削除したい場合はこれが方法です。

+0

を確認してください。パディングは、ボタンの内側のスペースです。 –

2

RelativeLayoutに切り替えることができます。そのレイアウトにはスペースがありません。

0

代わりにTableLayoutを使用すると、スペースを取り除くことができると思います。また、マージンに負の値を設定することもできます。

23

ボタンの色を変更してみてください。アンドロイドに固有のボタンのデフォルトのインターフェイスは実際にはそのサイズよりも小さく、見た目を凝縮しているためです。

変更それは黒か何かの背景だとあなたは、ボタンの実際のサイズが表示されます。

android:background="#000" 
+3

これは受け入れられるはずです。 Franziskusの答えは実際には良い習慣ではありません。 – Drag0

0

使用 "layout_marginLeft" & "layout_marginRigh" 背景ボタン

<LinearLayout 
    android:layout_width="fill_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:gravity="bottom" 
    android:orientation="horizontal" > 

    <Button 
     android:id="@+id/imageButton1" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="-5dp" 
     android:layout_marginLeft="-3dp" 
     android:layout_marginRight="-4dp" 
     android:layout_weight="1" 
     android:drawableTop="@drawable/create_mail" /> 

    <Button 
     android:id="@+id/bItem" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="-5dp" 
     android:layout_marginLeft="-4dp" 
     android:layout_marginRight="-4dp" 
     android:layout_weight="1" 
     android:drawableTop="@drawable/email_receive3" 
     android:onClick="OnClick" 
     android:text="@string/inbox" /> 


    <Button 
     android:id="@+id/imageButton2" 
     android:layout_width="0dp" 
     android:layout_height="match_parent" 
     android:layout_marginBottom="-5dp" 
     android:layout_marginLeft="-4dp" 
     android:layout_marginRight="-3dp" 
     android:layout_weight="1" 
     android:drawableTop="@drawable/email_trash" /> 


</LinearLayout> 
関連する問題