【问题标题】:I want to display the linear layout in the bottom of the screen.How do I make it align in bottom?我想在屏幕底部显示线性布局。如何使其底部对齐?
【发布时间】:2017-10-03 13:28:07
【问题描述】:

这是我的片段的 xml 代码。我可以在 recyclerview 上显示线性布局,但问题是,线性布局没有在屏幕底部对齐。 我应该使用相对布局而不是框架布局吗?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 tools:context="com.example.dell.pollachiclient.MyCartFragment">

 <android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view_cart"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    />
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_gravity="bottom"
    android:orientation="horizontal"
    android:background="#Fff"
     >

    <TextView
        android:id="@+id/setup_macroSavebtn"
        android:layout_width="0dp"
        android:layout_height="70dp"
        android:layout_gravity="start"
        android:gravity="center_vertical|center_horizontal"
        android:layout_weight="1"
        android:textColor="#000"
        android:background="#Fff"
        android:textStyle="normal"
        android:textSize="22sp"
        android:text="$500.00"/>

    <Button
        android:id="@+id/setup_macroCancelbtn"
        android:layout_width="0dp"
        android:layout_height="50dp"
        android:layout_gravity="center"
        android:layout_marginTop="20dp"
        android:gravity="center_vertical|center_horizontal"
        android:layout_margin="10dp"
        android:layout_weight="1"
        android:textColor="#fff"
        android:background="#FA631D"
        android:text="Checkout"/>
   </LinearLayout>

</FrameLayout>

Screenshot

【问题讨论】:

    标签: android xml android-fragments android-linearlayout


    【解决方案1】:

    使用RelativeLayout 代替FrameLayout 并使用

    android:layout_alignParentBottom="true"
    

    在您希望出现在底部的LinearLayout 中。

    【讨论】:

      【解决方案2】:

      用户RelativeLayout并使用

      <LinearLayout
          android:layout_width="match_parent"
          android:layout_height="70dp"
          android:orientation="horizontal"
          android:background="#Fff"
          android:layout_below="@id/recycler_view_cart"
           >
      

      【讨论】:

        【解决方案3】:
        <?xml version="1.0" encoding="utf-8"?>
        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/White">
        
            <Recycalvire
                android:id="@+id/container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_above="@+id/view_a" />
        
            <View
                android:id="@+id/view_a"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_above="@+id/bottom_layout"
                android:background="@color/col1"></View>
        
            <Linearlayout
                layout="@layout/buttom_menu"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true" />
        </RelativeLayout>
        

        【讨论】:

          【解决方案4】:

          按照@Nabin Bhandari 的回答试试这个

          <RelativeLayout
              android:layout_width="match_parent"
              android:layout_height="match_parent">
          
              <android.support.v7.widget.RecyclerView
                  android:id="@+id/recycler_view_cart"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"/>
          
              <LinearLayout
                  android:layout_width="match_parent"
                  android:layout_height="70dp"
                  android:layout_gravity="bottom"
                  android:background="#Fff"
                  android:layout_alignParentBottom="true"
                  android:orientation="horizontal">
          
                  <TextView
                      android:id="@+id/setup_macroSavebtn"
                      android:layout_width="0dp"
                      android:layout_height="70dp"
                      android:layout_gravity="start"
                      android:layout_weight="1"
                      android:background="#Fff"
                      android:gravity="center_vertical|center_horizontal"
                      android:text="$500.00"
                      android:textColor="#000"
                      android:textSize="22sp"
                      android:textStyle="normal" />
          
                  <Button
                      android:id="@+id/setup_macroCancelbtn"
                      android:layout_width="0dp"
                      android:layout_height="50dp"
                      android:layout_gravity="center"
                      android:layout_margin="10dp"
                      android:layout_marginTop="20dp"
                      android:layout_weight="1"
                      android:background="#FA631D"
                      android:gravity="center_vertical|center_horizontal"
                      android:text="Checkout"
                      android:textColor="#fff" />
          
              </LinearLayout>
          
          </RelativeLayout>
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2021-10-07
            • 2014-01-05
            • 2018-06-18
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2021-12-28
            相关资源
            最近更新 更多