Android LinearLayout底部的按钮
我正在制作一个应用程序,其中我有一个Android LinearLayout底部的按钮,android,xml,android-layout,Android,Xml,Android Layout,我正在制作一个应用程序,其中我有一个回收视图。我还添加了一个按钮,但没有显示。见左图。我现在想做的是使回收视图可见,如右图所示。我怎样才能做到这一点 在这些照片下,您可以看到我的xml代码。我希望循环视图是相对的/动态的 问题在于,您将cardwiew高度设置为match\u parent,因此它占据了整个屏幕。最好对这些类型的布局使用ConstraintLayout,但您也可以通过以下方式进行修复: <?xml version="1.0" encoding=&quo
回收视图
。我还添加了一个按钮,但没有显示。见左图。我现在想做的是使回收视图可见,如右图所示。我怎样才能做到这一点
在这些照片下,您可以看到我的xml代码。我希望循环视图是相对的/动态的
问题在于,您将
cardwiew
高度设置为match\u parent
,因此它占据了整个屏幕。最好对这些类型的布局使用ConstraintLayout,但您也可以通过以下方式进行修复:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context="com.test.test.MainActivity"
android:orientation="vertical"
android:background="@color/colorAccent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<androidx.cardview.widget.CardView
android:id="@+id/cardViewMiddle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
app:cardCornerRadius="15dp">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.core.widget.NestedScrollView>
</androidx.cardview.widget.CardView>
<Button
android:id="@+id/btnCheckout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/round_corner"
android:backgroundTint="@color/colorPrimaryDark"
android:elevation="16dp"
android:text="START"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
注:我仅将CardView的布局高度
更改为0dp
,然后添加了以下内容:
android:layout\u weight=“1”
这将告诉布局尽可能伸展(同时不覆盖其下方的其他元素)。非常感谢!几分钟后我会接受这个答案。祝你万事如意,白昼/黑夜愉快!♥
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
tools:context="com.test.test.MainActivity"
android:orientation="vertical"
android:background="@color/colorAccent">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"/>
<androidx.cardview.widget.CardView
android:id="@+id/cardViewMiddle"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginRight="20dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:layout_weight="1"
app:cardCornerRadius="15dp">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent">
</androidx.recyclerview.widget.RecyclerView>
</androidx.core.widget.NestedScrollView>
</androidx.cardview.widget.CardView>
<Button
android:id="@+id/btnCheckout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/round_corner"
android:backgroundTint="@color/colorPrimaryDark"
android:elevation="16dp"
android:text="START"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>