问题描述
我得到了这个相对布局,并且在android studio的设计屏幕上看起来不错
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:padding="8dp"
tools:context="com.checking.movi.movioperations.CartItems">
<TextView
android:id="@+id/txtcartprod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Productos seleccionados:"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_cart"
android:layout_width="match_parent"
android:layout_height="649dp"
android:layout_below="@+id/txtcartprod"
/>
<Button
android:id="@+id/btn_placeorder"
style="?android:attr/buttonStyleSmall"
android:layout_below="@+id/recycler_cart"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/mybutton"
android:text="Continuar"
android:textColor="#ffffff" />
</RelativeLayout>
但是当我在电话上进行测试时,如果我减小了recyclerview的尺寸,按钮就会出现在屏幕上,但是它确实出现了吗?你们能给我一点帮助吗?不知道告诉它保持3亮。在同一屏幕上
解决方法
以dp(或像素)为view
s设置宽度和高度不是正确的方法。因为屏幕尺寸在所有设备中都不相同。 Android Studio的“设计”选项卡在高度大于手机的Pixel手机中显示您的布局。因此,您无法在手机中看到该按钮。
我已在您的按钮上添加了一行,并删除了另一行
添加了此内容
android:layout_alignParentBottom="true"
删除此:
android:layout_below="@+id/txtcartprod"
将RecyclerView
的高度更改为match_parent
(以取决于屏幕尺寸):
android:layout_height="match_parent"
并添加以下行:
android:layout_above= "@id/btn_placeorder"
最终版本:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:padding="8dp"
tools:context="com.checking.movi.movioperations.CartItems">
<TextView
android:id="@+id/txtcartprod"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Productos seleccionados:"
/>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_cart"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above= "@id/btn_placeorder"
android:layout_below="@+id/txtcartprod"
/>
<Button
android:id="@+id/btn_placeorder"
style="?android:attr/buttonStyleSmall"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/mybutton"
android:text="Continuar"
android:textColor="#ffffff" />
</RelativeLayout>
希望您能理解我所做的所有更改。如果您有困难,请随时在评论中提问。