这里不允许使用元素LinearLayout-在RelativeLayout内部

问题描述 投票:0回答:1

我不断收到RelativeLayout对象中不允许使用LinearLayout的错误。我正在尝试创建一个多过滤器的搜索栏。该LinearLayout旨在在搜索栏中保留不同的元素。这是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:card_view="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#212121"
        android:minHeight="?attr/actionBarSize">


        <TextView
            android:id="@+id/toolbar_title"
            style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:text="@string/app_name"
            android:textColor="#FFF" />


    </androidx.appcompat.widget.Toolbar>


    <RelativeLayout
        android:id="@+id/view_search"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#50000000"
        android:clickable="true"
        android:visibility="invisible">

        <ProgressBar
            android:id="@+id/marker_progress"
            style="?android:attr/progressBarStyle"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_centerInParent="true"
            android:indeterminate="true"
            android:visibility="gone" />
    </RelativeLayout>

    <ListView
        android:id="@+id/listContainer"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#fff"
        android:clipToPadding="false"
        android:divider="#fff"
        android:paddingTop="56dp"
        android:visibility="gone" />

    <androidx.appcompat.widget.CardView
        android:id="@+id/card_search"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="4dp"
        android:visibility="invisible"
        card_view:cardCornerRadius="2dp">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <LinearLayout
                android:id="@+id/linearLayout_search"
                android:layout_width="match_parent"
                android:layout_height="48dp">

                <ImageView
                    android:id="@+id/image_search_back"
                    android:layout_width="48dp"
                    android:layout_height="48dp"
                    android:background="?android:attr/selectableItemBackground"
                    android:clickable="true"
                    android:padding="12dp"
                    android:src="@mipmap/ic_arrow_back" />

                <EditText
                    android:id="@+id/edit_text_search"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:background="#fff"
                    android:focusable="true"
                    android:gravity="center_vertical"
                    android:hint="@string/search_restaurants_and_cuisines"
                    android:imeOptions="actionSearch"
                    android:inputType="textCapWords"
                    android:maxLines="1"
                    android:paddingLeft="12dp"
                    android:paddingRight="8dp" />

            </LinearLayout>

            <View
                android:id="@+id/line_divider"
                android:layout_width="match_parent"
                android:layout_height=".5dp"
                android:layout_below="@+id/linearLayout_search"
                android:background="#eee" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_below="@+id/line_divider"
                android:divider="#FFFFFF" />
        </RelativeLayout>
    </androidx.appcompat.widget.CardView>


    <TextView
        android:id="@+id/txtNoResultsFound"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:gravity="center"
        android:padding="@dimen/activity_horizontal_margin"
        android:text="@string/no_results_found" />


    <ListView
        android:id="@+id/listView"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar"
        android:layout_marginBottom="@dimen/corners_small_value"
        android:layout_marginLeft="@dimen/corners_small_value"
        android:layout_marginRight="@dimen/corners_small_value">

    </ListView>

    <View
        android:id="@+id/toolbar_shadow"
        android:layout_width="match_parent"
        android:layout_height="4dp"
        android:layout_below="@+id/toolbar"
        android:background="@drawable/toolbar_shadow" />
</RelativeLayout>

为什么会这样?我确定它在更新的androidx CardView中,所以不确定为什么在CardView的RelativeLayout中仍然不允许LinearLayout。

android android-layout android-linearlayout android-relativelayout
1个回答
0
投票

CardView标签中似乎有错字:

<androidx.appcompat.widget.CardView

应该看起来像这样:

<androidx.cardview.widget.CardView ...

(用.appcompat.替换.cardview.

© www.soinside.com 2019 - 2024. All rights reserved.