【问题标题】:How to align 3 buttons to the bottom of layout?如何将 3 个按钮对齐到布局的底部?
【发布时间】:2014-01-02 19:04:43
【问题描述】:

我有一个线性垂直布局,其中有一个 TextView。 三个按钮排成一行。 我想把这 3 个按钮放在布局的底部。 我尝试了底部布局,但它似乎不起作用

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"

android:orientation="vertical" >

<TextView
    android:id="@+id/msgTextView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="Large Text"
    android:textAppearance="?android:attr/textAppearanceLarge" />

<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" >

    <Button
        android:id="@+id/previousButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:text="Previous" />

    <Button
        android:id="@+id/shareButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="Share" />

    <Button
        android:id="@+id/nextButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:text="Next" />
</RelativeLayout>

在这种情况下,按钮位于文本视图下方,而不是底部。

【问题讨论】:

    标签: android android-layout alignment android-relativelayout


    【解决方案1】:
    Try this>>>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical" >
    
        <TextView
            android:id="@+id/msgTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal" 
            android:layout_alignParentBottom="true">
    
            <Button
                 android:id="@+id/previousButton"
                 android:layout_width="0dp" 
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
                 android:text="Previous" />
    
            <Button
                android:id="@+id/shareButton"
                android:layout_width="0dp" 
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="Share" />
    
            <Button
                android:id="@+id/nextButton"
                android:layout_width="0dp" 
                android:layout_weight="1"
                android:layout_height="wrap_content"
                android:text="Next" />
        </LinearLayout>
    </RelativeLayout>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多