目前我有一个代码,我有一个recyclerview和cardview。 recyclerview适配器将显示列表卡,对于单个卡,数据将不同。这个问题来了。一旦我运行我的应用程序,我将收到requestLayout() improperly called by android.widget.LinearLayout
警告,此警告将中断我的应用程序流程,因为在出现以下警告后我无法启动任何活动。下面是我的logcat和xml。谢谢。
Logcat
05-24 16:21:40.065 30277-30277/com.jobforhire.mobile W/View: requestLayout() improperly called by android.widget.LinearLayout{d42d2b7 V.E...... ......I. 0,0-0,0 #7f0e00ce app:id/card_location_container} during layout: running second layout pass
05-24 16:21:40.065 30277-30277/com.jobforhire.mobile W/View: requestLayout() improperly called by android.widget.LinearLayout{231aa24 V.E...... ......I. 0,0-0,0 #7f0e00d1 app:id/card_jobtype_container} during layout: running second layout pass
05-24 16:21:40.065 30277-30277/com.jobforhire.mobile W/View: requestLayout() improperly called by android.widget.LinearLayout{cd4998d V.E...... ......I. 0,0-0,0 #7f0e00ce app:id/card_location_container} during layout: running second layout pass
05-24 16:21:40.065 30277-30277/com.jobforhire.mobile W/View: requestLayout() improperly called by android.widget.LinearLayout{d5c8742 V.E...... ......I. 0,0-0,0 #7f0e00d1 app:id/card_jobtype_container} during layout: running second layout pass
05-24 16:21:40.065 30277-30277/com.jobforhire.mobile W/View: requestLayout() improperly called by android.widget.LinearLayout{a7e353 V.E...... ......I. 0,0-0,0 #7f0e00ce app:id/card_location_container} during layout: running second layout pass
05-24 16:21:40.065 30277-30277/com.jobforhire.mobile W/View: requestLayout() improperly called by android.widget.LinearLayout{3f14490 V.E...... ......I. 0,0-0,0 #7f0e00d1 app:id/card_jobtype_container} during layout: running second layout pass
在进一步查看代码后,我发现这是我的LinearLayout(card_location_container& card_jobtype_container)卡片视图产生问题。我尝试更改为RelativeLayout
,但整个CardView
消失了。
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="8dp"
android:gravity="center_horizontal"
android:padding="25dp"
card_view:cardBackgroundColor="@color/cardview_light_background"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/offer_image"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:contentDescription=""
android:scaleType="centerCrop"
tools:ignore="ContentDescription"/>
<TextView
android:id="@+id/job_card_title"
style="@style/ShadowText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:text="Job Title"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="30sp"
android:textStyle="bold"
android:layout_above="@+id/left_image"
android:layout_centerHorizontal="true" />
<TextView
android:id="@+id/job_card_company_name"
style="@style/ShadowText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="11dp"
android:text="Company Name"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="28sp"
android:textStyle="bold"
android:layout_below="@+id/right_image"
android:layout_centerHorizontal="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/job_card_company_name"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:orientation="horizontal"
android:id="@+id/card_location_container"
android:layout_centerVertical="true">
<ImageView
android:id="@+id/job_card_image_location"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginRight="5dp"
card_view:srcCompat="@drawable/ic_location_on_black" />
<TextView
android:id="@+id/job_card_company_location"
style="@style/ShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Company Location"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/card_jobtype_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/card_location_container"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/job_card_image_job_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:layout_weight="1"
card_view:srcCompat="@drawable/ic_action_work" />
<TextView
android:id="@+id/job_card_job_type"
style="@style/ShadowText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:text="Job Type"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<ImageView
android:id="@+id/right_image"
style="@style/ShadowText"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="186dp"
android:src="@drawable/job_card_apply"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/left_image"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_alignTop="@+id/right_image"
android:layout_centerHorizontal="true"
android:layout_gravity="center_vertical"
android:src="@drawable/job_card_reject"
tools:ignore="ContentDescription" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
android:background="@color/white">
</RelativeLayout>
答案 0 :(得分:0)
尝试使用此布局并根据需要进行排列
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="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.support.v7.widget.CardView
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
card_view:cardBackgroundColor="@color/cardview_light_background"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="4dp"
card_view:cardUseCompatPadding="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:orientation="vertical"
android:padding="25dp"
android:textAlignment="center">
<ImageView
android:id="@+id/offer_image"
android:layout_width="match_parent"
android:layout_height="100dp"
android:adjustViewBounds="true"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/job_card_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Job Title"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:id="@+id/job_card_company_name"
style="@style/ShadowText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Company Name"
android:textAlignment="center"
android:textColor="@color/white"
android:textSize="28sp"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/card_location_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/job_card_image_location"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginEnd="10dp"
android:src="@drawable/ic_location_on_black" />
<TextView
android:id="@+id/job_card_company_location"
style="@style/ShadowText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Company Location"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="@+id/card_jobtype_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="@+id/job_card_image_job_type"
android:layout_width="28dp"
android:layout_height="28dp"
android:layout_marginEnd="10dp"
card_view:srcCompat="@drawable/ic_action_work" />
<TextView
android:id="@+id/job_card_job_type"
style="@style/ShadowText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Job Type"
android:textColor="@color/white"
android:textSize="24sp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="100dp">
<ImageView
android:id="@+id/left_image"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_margin="5dp"
android:layout_height="40dp"
android:src="@drawable/job_card_reject"
tools:ignore="ContentDescription" />
<ImageView
android:id="@+id/right_image"
style="@style/ShadowText"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_margin="5dp"
android:layout_height="40dp"
android:src="@drawable/job_card_apply"
tools:ignore="ContentDescription" />
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_weight="1"
android:background="@color/white">
</RelativeLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>