android-如何将带有突出显示颜色的文本添加到ImageView

android-如何将带有突出显示颜色的文本添加到ImageView,第1张

概述我试图将具有突出显示颜色的文本添加到ImageView中,我进行了一些搜索,但发现此answer并成功应用了它,但是我需要使图像中具有黑色的文本显示背景突出显示destination当前的XML<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.c

我试图将具有突出显示颜色的文本添加到ImageVIEw中,我进行了一些搜索,但发现此answer并成功应用了它,但是我需要使图像中具有黑色的文本显示背景突出显示

destination

当前的XML

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content"    androID:orIEntation="vertical">    <ImageVIEw        androID:ID="@+ID/postimage"        androID:layout_wIDth="match_parent"        androID:layout_height="125dp"        androID:layout_margin="2dp"        androID:scaleType="centerCrop"        androID:src="@mipmap/ic_launcher" />    <TextVIEw        androID:ID="@+ID/postTitle"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_alignStart="@ID/postimage"        androID:layout_alignEnd="@ID/postimage"        androID:layout_alignRight="@ID/postimage"        androID:layout_alignleft="@ID/postimage"        androID:layout_aligntop="@+ID/postimage"        androID:layout_alignBottom="@+ID/postimage"        androID:layout_margin="1dp"        androID:ellipsize="end"        androID:gravity="center|bottom"        androID:maxlines="2"        androID:text="Hello"        androID:textcolor="@color/white"        androID:textSize="14sp" /></relativeLayout>

解决方法:

简单的方法是:将背景色添加到文本视图并基于透明度设置Alpha值.

    <relativeLayout    androID:layout_wIDth="wrap_content"    androID:layout_height="wrap_content">    <ImageVIEw        androID:ID="@+ID/image"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:src="@drawable/my_image"        />    <TextVIEw        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="lasdfJsdfjlsdkfj"        androID:background="@androID:color/black"        androID:textcolor="@androID:color/white"        androID:layout_alignBottom="@ID/image"        androID:layout_alignleft="@ID/image"        androID:textSize="18sp"        androID:layout_alignRight="@ID/image"        androID:Alpha="0.5"/></relativeLayout>
总结

以上是内存溢出为你收集整理的android-如何将带有突出显示颜色的文本添加到ImageView全部内容,希望文章能够帮你解决android-如何将带有突出显示颜色的文本添加到ImageView所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1081714.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存