gpt4 book ai didi

java - LinearLayout原因 "requestLayout() improperly called by android.widget.LinearLayout"

转载 作者:太空宇宙 更新时间:2023-11-04 11:30:38 26 4
gpt4 key购买 nike

目前我有一个代码,其中有一个 recyclerview 和一个cardview。 recyclerview 适配器将显示卡片列表,对于个别卡片,数据会有所不同。问题就来了。运行应用程序后,我将收到 android.widget.LinearLayout 错误调用 requestLayout() 警告,并且此警告将中断我的应用程序流程,因为出现以下警告后我无法启动任何 Activity 。下面是我的 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)card View 产生了问题。我尝试更改为 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>

布局最初如下所示: enter image description here

如果我把它改成RelativeLayout enter image description here

最佳答案

尝试使用此布局并根据需要进行排列

<?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>

关于java - LinearLayout原因 "requestLayout() improperly called by android.widget.LinearLayout",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43840176/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com