簡體   English   中英

在Android上列出布局,如何使按鈕右對齊?

[英]List Layout on Android, how to make buttons right-aligned?

我一直在尋找使按鈕右對齊的方法,但沒有成功。 這里需要一些幫助。

<LinearLayout android:id="@+id/categoryRowLayout"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <TextView android:text="category" android:id="@+id/categoryRow"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
    </TextView>
    <Button android:text="Edit" android:id="@+id/editCategoryBtn"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:onClick="editCategoryHandler">
    </Button>
    <Button android:text="Delete" android:id="@+id/deleteCategoryBtn"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:onClick="deleteCategoryHandler">
    </Button>

</LinearLayout>

截圖:

在此輸入圖像描述

    <RelativeLayout android:id="@+id/categoryRowLayout"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <TextView android:text="category" android:id="@+id/categoryRow"
            android:layout_width="wrap_content" android:layout_height="wrap_content">
        </TextView>
        <Button android:text="Edit" android:id="@+id/editCategoryBtn"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:onClick="editCategoryHandler"
            android:layout_toLeftOf="@+id/deleteCategoryBtn"
    >
        </Button>
        <Button android:text="Delete" android:id="@+id/deleteCategoryBtn"
            android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:onClick="deleteCategoryHandler"
            android:layout_alignParentRight="true"
    >
        </Button>

</RelativeLayout>

試試這個,我使用相對布局和對齊刪除按鈕到右邊,並編輯刪除按鈕左側的按鈕。

作為替代方案,您可以剛剛添加到TextView中:

android:layout_weight="1"

暫無
暫無

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

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