Element LinearLayout is not allowed in CardView

2019-06-17 15:36发布

Note: PLEASE READ THE QUESTION before mark it as duplicate! I've mentioned that the similar question has not solved my problem.


I am using android.support.v7.widget.CardView for my layout xml. However when I place a LinearLayout within the CardView, Android Studio gives me the following error "Element LinearLayout is not allowed here".

In fact ANY types of widgets (like TextView) would cause this error, I have tried solutions from LinearLayout flagged if used in CardView link, which was to restart Android Studio. But it did not work. Below is my xml code:

<?xml version="1.0" encoding="utf-8"?>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout>

    </LinearLayout>

</android.support.v7.widget.CardView>

And I will also post a screenshot!

enter image description here

What could be the problem??

2条回答
神经病院院长
2楼-- · 2019-06-17 16:18

So, a collection of suggestions, just to be sure:

  • restart AS
  • invalidating Caches & restart
  • Check if the right dependencies are added
  • clean & rebuild of project
  • try same code in another file/project
  • trying to find a backup of your project
  • maybe computer reboot
查看更多
爷的心禁止访问
3楼-- · 2019-06-17 16:27

make sure that you did not inter constrains(magic stick) to card view because it will add constrains to card view and prevent any linear layout.

查看更多
登录 后发表回答