Overlay over an ImageView on Android(在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Android 上覆盖 ImageView
基础教程推荐
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
