android - 如何设置放置在 ImageView 上的 TextView 的背景不透明度

标签 android background android-imageview textview opacity

我想在名称上有透明背景的情况下实现以下结果:

Background on the name

到目前为止,这就是我所做的(忽略图像周围的黑色边框):

current result

我想要一个透明背景(实际上是一个调整了不透明度的彩色背景)。

这是我一直在使用的 XML 代码:

<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp">

<ImageView
    android:id="@+id/iconItem"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="center"
    android:src="@drawable/shout_ic"/>
<TextView
    android:id="@+id/textItem"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:layout_alignBottom="@+id/iconItem"
    android:paddingBottom="5dip"
    android:textSize="10sp"
    android:textColor="#FFF"/>
</RelativeLayout>

任何人都可以指出如何实现这些目标的正确方向吗?谢谢

最佳答案

在您的 TextView 定义中,添加:

android:background="#8888"

888 是中灰色 (888888),8 是中 alpha (88)

android:background="#8000"

000 是黑色 (000000),8 是中间 alpha (88)

关于android - 如何设置放置在 ImageView 上的 TextView 的背景不透明度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20881445/

相关文章:

java - 如何将 fragment 的上下文转换为 LifecycleOwner?

android - 如何在android中将一个线性布局设置在另一个线性布局下方

android - 我怎么知道一个成就是否在android中完成?

android - 如何更改 Android ViewPager 背景颜色?

android - ImageView 适合高度保持纵横比

android - 如何制作星形和圆形等自定义形状的图像?

android - 如何告诉 Gradle 在哪里搜索 Android 的支持库?

css - 背景仅覆盖移动页面的一半

java - 如何创建看起来 TextView 比它大的列表项?

android - 如何使 ImageView float 在 LinearLayout 上方?