【发布时间】:2017-02-25 17:50:59
【问题描述】:
我知道以前有人问过类似的问题,但我认为我的情况有所不同。 So I'm trying to make a playlist using a RecyclerView and when a song is selected I want the circular image which holds the Image for the song to change to a tick sign while the original image can be seen faded in the background.我已经准备好了刻度图。
如何在现有的 ImageView 上动态添加此图像?将一张图片放在后台的方法对我来说不是一个解决方案,因为音乐图片文件是从 Realm 动态加载的,因此不能作为背景。
我的 RecyclerView 项目的 XML 代码如下:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:paddingRight="10dp"
android:paddingLeft="30dp"
>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="120dp"
android:layout_height="120dp"
android:layout_gravity="start"
android:transitionName="albumArt"
android:id="@+id/album_art"
android:scaleType="centerCrop"
android:src="@color/colorPrimary"/>
<LinearLayout
android:layout_width="fill_parent"
android:gravity="right"
android:paddingLeft="20dp"
android:orientation="vertical"
android:layout_marginTop="20dp"
android:layout_height="wrap_content">
<TextView
android:id="@+id/data"
android:layout_width="match_parent"
android:fontFamily="sans-serif"
android:textColor="#ffffff"
android:text="Music Name"
android:textSize="17sp"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/data_album"
android:layout_width="match_parent"
android:fontFamily="sans-serif"
android:textColor="#bfe0e0e0"
android:textSize="14sp"
android:text="Music Artist"
android:layout_height="wrap_content"
/>
</LinearLayout>
如何从 java 代码中动态执行此操作?这可以以某种方式使用set visibility 来完成吗?如果是,请解释执行此操作的新方法。
【问题讨论】:
-
use
LayerDrawableclass: "管理其他 Drawable 数组的 Drawable。这些是按数组顺序绘制的,因此索引最大的元素将绘制在顶部。"