在页面底部添加 checkout 按钮

oxiaedzo  于 2021-07-12  发布在  Java
关注(0)|答案(3)|浏览(278)

我试图在我的下一页的底部显示一个“ checkout ”按钮 RecyclerView .
我的xml文件如下所示:

<androidx.drawerlayout.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light"
    android:id="@+id/drawer_layout"
    tools:context=".Cart">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/Cart"
            android:gravity="center"
            android:fontFamily="@font/poppinsbold"
            android:textSize="20dp"
            android:textStyle="bold"
            android:layout_marginTop="20dp"
            android:layout_marginLeft="10dp"/>

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="555dp"
            android:layout_marginBottom="500px"/>

        <Button
            android:id="@+id/checkout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:text="Checkout" />

    </LinearLayout>

    <RelativeLayout

        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white">

        <include
            layout="@layout/main_nav_drawer"/>
    </RelativeLayout>

</androidx.drawerlayout.widget.DrawerLayout>

不幸的是,当我应用更改时,产品看起来很棒,但是按钮没有显示。
我怎样才能让它出现?
非常感谢。

pbwdgjma

pbwdgjma1#

你需要
拆下发动机的底部衬垫 RecyclerView 不指定 RecyclerView ,而是使用 RecyclerView 展开到按钮
删除 android:layout_alignParentBottom="true"Button 因为它和 LinearLayout 应用:

<?xml version="1.0" encoding="utf-8"?>

<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/background_light">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="20dp"
            android:fontFamily="@font/poppinsbold"
            android:gravity="center"
            android:text="@string/Cart"
            android:textSize="20dp"
            android:textStyle="bold" />

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:layout_height="0dp" />

        <Button
            android:id="@+id/checkout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Checkout" />

    </LinearLayout>

    <RelativeLayout
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="@android:color/white">

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

    </RelativeLayout>

</androidx.drawerlayout.widget.DrawerLayout>
ldxq2e6h

ldxq2e6h2#

问题在于recyclerview的layout\u marginbottom属性。500像素?!你在开玩笑吧?8dp就足够了。

oo7oh9g9

oo7oh9g93#

潜在选择:
根据屏幕分辨率和constraintlayout动态设置边距。以下是一些示例:
https://developer.android.com/reference/androidx/constraintlayout/widget/constraintlayout?hl=id#relativepositioning
https://constraintlayout.com/layouts/percentlayout.html
根据所需比例动态设置边距。下面是一个例子:https://stackoverflow.com/a/16200839/9772953
删除recyclerview的下边距。
考虑更新你的recyclerview的下边距,用更小的东西代替它。

相关问题