Display UI widget in Cardview in android L

I am trying to create an application in cardview, cardview contains two text images that need to be placed next to each other, but text views overlap each other. Is there any mechanism for placing elements like its made in RelativeLayout (layout_below or layout_toRightOf) for Cardviews. I can do this by adding shadows to Relativelayout and making it look like Cardview, I want to do it in Cardview.

My layout code is below:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:background="@android:color/black" android:layout_height="match_parent"> <android.support.v7.widget.CardView android:id="@+id/card_view" android:background="@color/white" android:layout_width="200dp" android:layout_height="200dp"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="match_parent" android:text="Textview one" android:gravity="center" android:textSize="36sp" /> <TextView android:id="@+id/info_text1" android:layout_width="match_parent" android:layout_height="match_parent" android:text="Textview two" android:gravity="center" android:textSize="36sp" /> </android.support.v7.widget.CardView> </RelativeLayout> 

It is currently displayed as shown in the figure:

enter image description here

+6
source share
1 answer

From the description of CardView

CardView extends the FrameLayout class and allows you to display information inside cards that have a constant look in any application. CardView widgets can have shadows and rounded corners.

As you probably know, FrameLayout no restrictions or relationships between positioning views. They will be displayed one above the other. If you want to use a different hierarchy inside CardView , just use whatever layout you want inside. For instance:

 <android.support.v7.widget.CardView android:id="@+id/card_view" android:background="@color/white" android:layout_width="200dp" android:layout_height="200dp"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/info_text" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Textview one" android:gravity="center" android:textSize="36sp" /> <TextView android:id="@+id/info_text1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Textview two" android:gravity="center" android:textSize="36sp" /> </LinearLayout> </android.support.v7.widget.CardView> 

Treat CardView only as an external decoration, and you can use ANY layout inside. Therefore, if LinearLayout not suitable, you can use RelativeLayout , etc.

+18
source

Source: https://habr.com/ru/post/974349/


All Articles