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!
What could be the problem??
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" .
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.
↳ 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.
So, a collection of suggestions, just to be sure:
Just replace android.support.v7.widget.CardView
with androidx.cardview.widget.CardView
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With