Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Element LinearLayout is not allowed in CardView

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

like image 346
Joel Min Avatar asked Nov 12 '15 13:11

Joel Min


People also ask

How do you declare a Linearlayout?

To create a linear layout in which each child uses the same amount of space on the screen, set the android:layout_height of each view to "0dp" (for a vertical layout) or the android:layout_width of each view to "0dp" (for a horizontal layout). Then set the android:layout_weight of each view to "1" .

How do I fix the view to the bottom of Linearlayout?

If you have a relative layout that fills the whole screen you should be able to use android:layout_alignParentBottom to move the button to the bottom of the screen. If your views at the bottom are not shown in a relative layout then maybe the layout above it takes all the space.

What is Androidx CardView?

↳ androidx.cardview.widget.CardView. A FrameLayout with a rounded corner background and shadow. CardView uses elevation property on Lollipop for shadows and falls back to a custom emulated shadow implementation on older platforms.


2 Answers

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
like image 155
yennsarah Avatar answered Sep 30 '22 17:09

yennsarah


Just replace android.support.v7.widget.CardView with androidx.cardview.widget.CardView

like image 37
Vikram Kodag Avatar answered Sep 30 '22 16:09

Vikram Kodag