cardView内部relativeLayout在android中不显示内容
布局文件cardView内部relativeLayout在android中不显示内容,android,android-layout,Android,Android Layout,布局文件 如果我移动cardView的项目并与recyclerView平行,则只显示它。在当前情况下,屏幕上显示的是noting,而不是recyclerView项 如何在relativeLayout中使用cardView 我是否遗漏了任何android概念?这就是我使用RecyclerView和CardView的方式,这是为主要活动和RecyclerView项目制作单独布局的非常干净和标准的方式 activity_main.xml <RelativeLayout xmlns:and
如果我移动cardView的项目并与recyclerView平行,则只显示它。在当前情况下,屏幕上显示的是noting,而不是recyclerView项
如何在relativeLayout中使用cardView
我是否遗漏了任何android概念?这就是我使用RecyclerView和CardView的方式,这是为主要活动和RecyclerView项目制作单独布局的非常干净和标准的方式 activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GrayGood"
tools:context="faisal.example.recyclerview.MainActivity" >
<LinearLayout
android:id="@+id/toolBarContainer_ID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar_ID"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:background="@color/colorPrimary" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_ID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="?attr/actionBarSize" />
</RelativeLayout>
现在,将驻留在CardView中包装的RecyclerView行中的项目的布局
活动\u main\u row.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cardViewID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:clickable="true" //here make your recyclerItem row clickable
android:focusable="true"
card_view:cardCornerRadius="5dp" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground" //this will give you highlight effect when list item is pressed
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp" >
<CheckBox
android:id="@+id/applyWallet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apply wallet"
android:checked="true"
android:layout_above="@+id/mainText"
/>
<TextView
android:id="@+id/mainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="@color/primary_dark"
android:layout_centerHorizontal="true"
android:layout_above="@+id/placeOrderButton"
/>
<Button
android:id="@+id/placeOrderButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="PLACE ORDER"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
现在,项目将相互重叠,因此通过在=“@+id/yourView”下面指定布局_来设置它们
这是处理RecyclerView的常用方法,因为您需要在RecyclerAdapter类中使用物品支架的布局。
希望我能提供帮助或指导。这就是我使用RecyclerView和CardView的方式,对于主要活动和RecyclerView的项目来说,这是一种非常干净和标准的布局方式 activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/GrayGood"
tools:context="faisal.example.recyclerview.MainActivity" >
<LinearLayout
android:id="@+id/toolBarContainer_ID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<android.support.v7.widget.Toolbar
android:id="@+id/toolBar_ID"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
android:background="@color/colorPrimary" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView_ID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipToPadding="false"
android:paddingTop="?attr/actionBarSize" />
</RelativeLayout>
现在,将驻留在CardView中包装的RecyclerView行中的项目的布局
活动\u main\u row.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/cardViewID"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:clickable="true" //here make your recyclerItem row clickable
android:focusable="true"
card_view:cardCornerRadius="5dp" >
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground" //this will give you highlight effect when list item is pressed
android:orientation="vertical"
android:paddingBottom="10dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp" >
<CheckBox
android:id="@+id/applyWallet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apply wallet"
android:checked="true"
android:layout_above="@+id/mainText"
/>
<TextView
android:id="@+id/mainText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="@color/primary_dark"
android:layout_centerHorizontal="true"
android:layout_above="@+id/placeOrderButton"
/>
<Button
android:id="@+id/placeOrderButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="PLACE ORDER"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
现在,项目将相互重叠,因此通过在=“@+id/yourView”下面指定布局_来设置它们
这是处理RecyclerView的常用方法,因为您需要在RecyclerAdapter类中使用物品支架的布局。
希望我有帮助或指导。Agarwal,您好,请仔细阅读我的答案,如果对您有帮助,请回复。Agarwal,您好,请仔细阅读我的答案,如果对您有帮助,请回复。