Android 未应用布局重力底部

Android 未应用布局重力底部,android,android-layout,Android,Android Layout,下面是我的xml文件,我希望linearlayout位于底部,即布局重力底部。但它不起作用 即使在查看了针对这类问题给出的所有解决方案后,我也无法解决它。请帮忙 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_wid

下面是我的
xml
文件,我希望
linearlayout
位于底部,即布局重力底部。但它不起作用

即使在查看了针对这类问题给出的所有解决方案后,我也无法解决它。请帮忙

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/toolbar_layout" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerViewCart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"/>
     
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom" //----> not working
    android:orientation="horizontal">

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:layout_weight="1"
        android:orientation="vertical">

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/total"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/textViewTotalPrice"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="$23.00" />
    </LinearLayout>

    <Button
        android:id="@+id/buttonCheckout"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginEnd="20dp"
        android:layout_weight="1"
        android:background="@color/colorPrimary"
        android:drawableEnd="@drawable/ic_arrow_forward"
        android:paddingEnd="15dp"
        android:text="@string/checkout"
        android:textColor="@color/white" />
</LinearLayout>

试试这个

   <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

        <include layout="@layout/toolbar_layout" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/recyclerViewCart"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="10dp"
        android:layout_weight="1" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:layout_weight="1"
            android:orientation="vertical">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="total"
                android:textStyle="bold" />

            <TextView
                android:id="@+id/textViewTotalPrice"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="$23.00" />
        </LinearLayout>

        <Button
            android:id="@+id/buttonCheckout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginRight="20dp"
            android:background="@color/colorPrimary"
            android:drawableEnd="@drawable/ic_arrow_forward"
            android:paddingEnd="15dp"
            android:text="@string/checkout"
            android:textColor="@color/white" />


    </LinearLayout>

</LinearLayout>

在RecyclerView和LinearLayout之间放置空间布局

<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>


或者使用RelativeLayout而不是主线布局,请尝试以下代码。。改变这个

<Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include layout="@layout/toolbar_layout" />

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerViewCart"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="10dp"/>
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
  android:orientation="horizontal">

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_margin="20dp"
    android:layout_weight="1"
    android:orientation="vertical">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="tees"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/textViewTotalPrice"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="$23.00" />
</LinearLayout>

<Button
    android:id="@+id/buttonCheckout"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:layout_marginEnd="20dp"
    android:layout_weight="1"
    android:background="@color/colorPrimary"
    android:paddingEnd="15dp"
    android:text="Hello" />
 </LinearLayout>
</RelativeLayout>

</LinearLayout>


LinearLayout
方向垂直无法正常工作,那么我该怎么办?您期望的输出是什么@HetVigand?我希望在屏幕底部显示特定的线性布局。这不是我期望的输出@HetviGandhi您能否将您的预期结果作为问题中的图像共享我认为这是您预期的正确答案@HetviGandhi如果我不想在xml文件中使用相对布局怎么办?还有其他解决方案吗?根据您的xml代码,只有一个相对布局的解决方案。若知道,则使用约束布局,它将线性布局和相对布局相结合。