在 Android 上覆盖 ImageView [英] Overlay over an ImageView on Android

查看:18
本文介绍了在 Android 上覆盖 ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个来自网络的图像列表,我不知道它们是哪种颜色,我想在 ImageView 上放置一个文本.

So I have a list of images that come from the web, I don't know which color are they and I want to place a text over the ImageView.

我的想法是放置 ImageView,一个带有透明度渐变的图像覆盖在该 ImageView 及其上方的文本上.我想模仿这种行为:

My idea is to place the ImageView, an image overlay with transparency gradient over that ImageView and the text above it. I want to mimic this behaviour:

有没有办法通过 XML 做到这一点?

Is there anyway to do this via XML?

推荐答案

当您为列表项编写 XML 时,列表项会在任何 ListAdapter 的 getView(...) 中膨胀 你写的肯定能做到.

When you write the XML for your list items which get inflated in the getView(...) of whatever ListAdapter you've written you can surely do this.

列表项是这样的:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

  <ImageView
    android:layout_width="320dp"
    android:layout_height="240dp"
    android:background="#ACACAC"/>

  <RelativeLayout
    android:layout_width="320dp"
    android:layout_height="240dp"
    android:background="@drawable/gradient">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Here is your text"
        android:textColor="#000000"
        android:layout_alignParentBottom="true"/>

  </RelativeLayout>

</RelativeLayout>

然后你创建那个drawable/gradient.为此,您可以从这里回收答案.

Then you create that drawable/gradient. For that you can recycle the answer from here.

这篇关于在 Android 上覆盖 ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆