Reputation: 47
This is Textview :
<TextView
android:id="@+id/text_naer_me"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text=“Hello”
android:background="@drawable/rounded_white_border"
/>
This background resource
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke
android:width="1dp"
android:color="@color/light_gray" />
<solid android:color="@color/white" />
<corners android:radius="2dp" />
</shape>
current view is below
expected view is below
please suggest me how to achieve this i want make textview as card view you can see my given screen
Upvotes: 1
Views: 1044
Reputation: 204
There are lots of ways and here they are Use that which one suits you
Create your own drawable
border.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="@android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
and your_layout.xml
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:padding="10dp"
android:background="@drawable/border"
/>
You can also use use a drawable from android
android:background="@android:drawable/toast_frame"
or:
android:background="@android:drawable/dialog_frame"
or:
android:background="@android:drawable/dialog_holo_light_frame"
Use a 9-patch image with a shadow and set it as the background to your Linear layout
Use this website to create 9 patch with shadow
http://inloop.github.io/shadow4android/
Upvotes: 1
Reputation: 714
Use android:elevation="20dp" and background same effect like cardview without wrap cardview
<TextView
android:layout_margin="10dp"
android:elevation="20dp"
android:padding="20dp"
android:background="@drawable/background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
/>
Upvotes: 0