【问题标题】:Rounded corners with background image for text view in android studio带有背景图像的圆角,用于 android studio 中的文本视图
【发布时间】:2021-05-18 12:39:24
【问题描述】:

我有一个文本视图,我希望它的背景是图像,并且它的角也是圆角的。我通过创建一个可绘制文件来尝试过,但背景图像被溢出了。

 <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>

Output:

Example Output:

【问题讨论】:

  • 您能否展示一个您需要的示例输出
  • 我已经添加了示例输出。

标签: android image textview shapes xml-drawable


【解决方案1】:

LayerList 的官方 Android 文档一样

LayerDrawable 是一个可绘制对象,用于管理一组其他可绘制对象。列表中的每个可绘制对象都按照列表的顺序绘制 - 列表中的最后一个可绘制对象绘制在顶部。

意味着您的可绘制对象需要放置在圆形背景之后才能可见。

【讨论】:

  • 如果我在圆角背景之后放置可绘制图像项,那么它会与圆角重叠并显示整个图像。
猜你喜欢
  • 2020-05-11
  • 1970-01-01
  • 2020-10-08
  • 2019-11-14
  • 2012-06-16
  • 2016-03-18
  • 2020-10-25
  • 2021-11-04
  • 2012-02-29
相关资源
最近更新 更多