[英]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.