[英]Rounded corners with background image for text view in android studio
我有一个文本视图,我希望它的背景是图像,并且它的角也是圆角的。 我已经通过创建一个可绘制文件来尝试过,但是背景图像被溢出了。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
android:padding="5dp"
android:orientation="horizontal">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/colorPrimaryDark"
android:background="@drawable/drawable_file"
/>
</LinearLayout>
drawable_file.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list
xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<bitmap android:src="@drawable/img" />
</item>
<item>
<shape>
<stroke
android:width="1dp" />
<corners android:radius="50dp" />
</shape>
</item>
</layer-list>
与 LayerList 的官方 Android 文档一样
LayerDrawable 是一个可绘制的 object,它管理一系列其他可绘制对象。 列表中的每个可绘制对象都按照列表的顺序绘制——列表中的最后一个可绘制对象绘制在顶部。
这意味着您的可绘制对象需要放置在圆形背景之后才能可见。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.