[英]Android: how to make it no space between 2 button in a horizontal linearlayout
我發現即使我將layout_marginRight
和layout_marginLeft
設置layout_marginRight
,我也無法刪除2個按鈕之間的空格。 但是如果我將空間設置得更大,例如10 dp,那就更有意義了。 有什么方法可以解決嗎?
<?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>
請看布萊恩的答案 。 我的回答兩個按鈕重疊。 布萊恩斯答案顯示按鈕的實際大小。
只需將第一個按鈕的android:layout_marginRight
設置為"-8dip"
甚至更多。 比兩個按鈕之間的空間會變小。
嘗試更改按鈕的顏色,因為android原生的按鈕的默認界面實際上小於它的大小,並且它的中心適合使它看起來很酷。
將它的背景更改為黑色或其他東西,您將看到按鈕的實際大小。
android:background="#000"
您可以切換到RelativeLayout
。 該布局中沒有間距。
你將不得不設置android:layout_marginRight="0dip"
,你將不得不刪除帶有android:paddingRight="0dip"
的填充,其他按鈕必須將其更改為左值。 我猜你忘記了每個android元素默認都添加了一個填充。 這通常是一個好主意,但如果你想刪除它,這就是方法。
使用“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>
我認為如果你使用TableLayout,你可以擺脫空間。 如果它仍然在它們之間添加一些默認空間,則可以為邊距設置負值。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.