如何在 android 中使用后台资源将 textview 设为卡片视图
How to make textview as card view in android using background resource
这是 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"
/>
这个背景资源
<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>
当前视图在下方
enter image description here
预期观看次数低于
enter image description here
请建议我如何实现这一点我想将 textview 作为卡片视图你可以看到我给定的屏幕
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"
/>
方法有很多种,这里有适合你的方法
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>
和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"
或:
android:background="@android:drawable/dialog_frame"
或:
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
使用本网站创建9个带阴影的补丁
这是 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"
/>
这个背景资源
<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>
当前视图在下方
enter image description here
预期观看次数低于
enter image description here
请建议我如何实现这一点我想将 textview 作为卡片视图你可以看到我给定的屏幕
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"
/>
方法有很多种,这里有适合你的方法
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>
和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"
或:
android:background="@android:drawable/dialog_frame"
或:
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
使用本网站创建9个带阴影的补丁