I am trying to create an application in cardview, the cardview contains two textviews which needs to be placed next to each other, but the textviews are getting overlapped. Is there any mechanism to place elements like its done in RelativeLayout(layout_below or layout_toRightOf) for Cardviews. I am able to do this by adding shadows to the Relativelayout and making it look like Cardview, I want to do this in the 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>
Currently it is displayed like the picture attached:
From the description of CardView
CardView extends the FrameLayout class and lets you show information inside cards that have a consistent look on any app. CardView widgets can have shadows and rounded corners.
As you probably know, in FrameLayout
there are no constraints or relations between views positioning. They will be displayed one above each other. If you want to use different hierarchy inside a CardView
please just use any layout you want inside. For example:
<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 the CardView
only as an outer decoration and you can use ANY layout inside. So if LinearLayout
is not appropriate you can use RelativeLayout
etc.
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