1、设置eleavation值;
2、添加一个背景或者outline。
可以在xml中通过定义一个背景来设置outline:
<TextView
android:id="@+id/myview"
...
android:elevation="2dp"
android:background="@drawable/myrect" />
<!-- res/drawable/myrect.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#42000000" />
<corners android:radius="5dp" />
</shape>
也可以通过代码来创建一个outline:
/* Get the size of the shape from resources. */
int shapeSize = getResources().getDimensionPixelSize(R.dimen.shape_size)
/* Create a circular outline. */
mOutlineCircle = new Outline()
mOutlineCircle.setRoundRect(0, 0, shapeSize, shapeSize, shapeSize / 2)
/* Create a rectangular outline. */
mOutlineRect = new Outline()
mOutlineRect.setRoundRect(0, 0, shapeSize, shapeSize, shapeSize / 10)
为控件设置阴影效果,使用shape进行阴影效果绘制即可。 shape使用方法具体可自行百度。 你的采纳是我前进的动力, 记得好评和采纳,答题不易,互相帮助, 手机提问的朋友在客户端右上角评价点(满意)即可. 如果你认可我的回答欢迎分享,转载请注明来源:内存溢出
评论列表(0条)