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

查看:108
本文介绍了覆盖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?

推荐答案

当您为 getView(...)中的任何 ListAdapter 中的列表项编写XML时你写的你肯定可以这样做。

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>

然后创建可绘制/渐变。为此,您可以从此处回收答案。

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

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

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