在页面底部添加 checkout 按钮

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

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

  1. <androidx.drawerlayout.widget.DrawerLayout
  2. xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:layout_width="match_parent"
  6. android:layout_height="match_parent"
  7. android:background="@android:color/background_light"
  8. android:id="@+id/drawer_layout"
  9. tools:context=".Cart">
  10. <LinearLayout
  11. android:layout_width="match_parent"
  12. android:layout_height="match_parent"
  13. android:orientation="vertical">
  14. <include
  15. layout="@layout/main_toolbar"/>
  16. <TextView
  17. android:layout_width="match_parent"
  18. android:layout_height="wrap_content"
  19. android:text="@string/Cart"
  20. android:gravity="center"
  21. android:fontFamily="@font/poppinsbold"
  22. android:textSize="20dp"
  23. android:textStyle="bold"
  24. android:layout_marginTop="20dp"
  25. android:layout_marginLeft="10dp"/>
  26. <androidx.recyclerview.widget.RecyclerView
  27. android:id="@+id/recycler_view"
  28. android:layout_width="match_parent"
  29. android:layout_height="555dp"
  30. android:layout_marginBottom="500px"/>
  31. <Button
  32. android:id="@+id/checkout"
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:layout_alignParentBottom="true"
  36. android:text="Checkout" />
  37. </LinearLayout>
  38. <RelativeLayout
  39. android:layout_width="300dp"
  40. android:layout_height="match_parent"
  41. android:layout_gravity="start"
  42. android:background="@android:color/white">
  43. <include
  44. layout="@layout/main_nav_drawer"/>
  45. </RelativeLayout>
  46. </androidx.drawerlayout.widget.DrawerLayout>

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

pbwdgjma

pbwdgjma1#

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

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. xmlns:app="http://schemas.android.com/apk/res-auto"
  4. xmlns:tools="http://schemas.android.com/tools"
  5. android:id="@+id/drawer_layout"
  6. android:layout_width="match_parent"
  7. android:layout_height="match_parent"
  8. android:background="@android:color/background_light">
  9. <LinearLayout
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent"
  12. android:orientation="vertical">
  13. <include layout="@layout/main_toolbar" />
  14. <TextView
  15. android:layout_width="match_parent"
  16. android:layout_height="wrap_content"
  17. android:layout_marginLeft="10dp"
  18. android:layout_marginTop="20dp"
  19. android:fontFamily="@font/poppinsbold"
  20. android:gravity="center"
  21. android:text="@string/Cart"
  22. android:textSize="20dp"
  23. android:textStyle="bold" />
  24. <androidx.recyclerview.widget.RecyclerView
  25. android:id="@+id/recycler_view"
  26. android:layout_width="match_parent"
  27. android:layout_weight="1"
  28. android:layout_height="0dp" />
  29. <Button
  30. android:id="@+id/checkout"
  31. android:layout_width="wrap_content"
  32. android:layout_height="wrap_content"
  33. android:text="Checkout" />
  34. </LinearLayout>
  35. <RelativeLayout
  36. android:layout_width="300dp"
  37. android:layout_height="match_parent"
  38. android:layout_gravity="start"
  39. android:background="@android:color/white">
  40. <include layout="@layout/main_nav_drawer" />
  41. </RelativeLayout>
  42. </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的下边距,用更小的东西代替它。

相关问题