簡體   English   中英

如何在linearlayout中的按鈕之間留出空間

[英]how to make space between button in linearlayout

**我有一個按鈕,因為我想在所有按鈕之間放置空間,所以如果我在平板電腦上運行應用程序,則按鈕之間的空間將相等,我正在使用linearlayout,我知道這里有layout_weight選項,但是我不想拉伸圖標**

<LinearLayout
        android:orientation="horizontal"
        android:gravity="bottom|right"
        android:background="#00ffffff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:id="@+id/linearLayout">



        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/call"
            android:background="@drawable/layoutcornerbend"
            android:layout_gravity="bottom"
            android:src="@drawable/e"
            />


        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/layoutcornerbend"
            android:id="@+id/navigation"
            android:layout_gravity="bottom"
            android:src="@drawable/navi"/>



        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/layoutcornerbend"
            android:id="@+id/stream"
            android:layout_gravity="bottom"
            android:src="@drawable/appstream"/>
    </LinearLayout>

這是@Cyril Mottier撰寫的精彩文章,可在您使用LinearLayout時增加間距。 請遵循此。 http://cyrilmottier.com/2014/11/17/grid-spacing-on-android/

基本上,您只需要使用參數:

android:divider

使用余量

<LinearLayout
        android:orientation="horizontal"
        android:gravity="bottom|right"
        android:background="#00ffffff"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:layout_alignParentBottom="true"
        android:id="@+id/linearLayout">



        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/call"
            android:background="@drawable/layoutcornerbend"
            android:layout_gravity="bottom"
            android:src="@drawable/e"
            **android:layout_marginRight="10dp"**
            />


        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/layoutcornerbend"
            android:id="@+id/navigation"
            android:layout_gravity="bottom"
            **android:layout_marginRight="10dp"**
            android:src="@drawable/navi"/>



        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/layoutcornerbend"
            android:id="@+id/stream"
            android:layout_gravity="bottom"
            android:src="@drawable/appstream"/>
    </LinearLayout>
<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="2"
        android:layout_alignParentBottom="true"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:orientation="horizontal">


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="log in"
            android:textAllCaps="true"
            android:layout_weight="1"
            android:background="#E0B13B"/>

        <view
            android:layout_width="10dp"
            android:layout_height="0dp"/>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="register"
            android:textAllCaps="true"
            android:layout_weight="1"
            android:background="#67A22C"/>

    </LinearLayout>>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM