如何使用滑动将图像加载到图层项目中

问题描述 投票:1回答:1

在我的应用程序中,我需要一个带有自定义形状的imageView。我用可绘制的layer-list创造了我的形状。

这是我的layer-list代码:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@color/colorPrimary"/>

    <item
        android:id="@+id/logo">
        <bitmap android:src="@drawable/temp_image"
                android:gravity="center" android:alpha="1"/>
    </item>

    <item android:top="-150dp"
          android:bottom="120dp"
          android:left="0dp">
        <rotate
            android:fromDegrees="-45"
            android:pivotX="0%"
            android:pivotY="130%">
            <shape
                android:shape="rectangle">
                <solid
                    android:color="@color/colorBottomMenuDark"/>
            </shape>
        </rotate>
    </item>
</layer-list>

这很好但我需要使用glide动态地将图像加载到位图(具有日志ID的项目)。

我怎样才能做到这一点?

android user-interface android-xml android-glide
1个回答
0
投票

您无法以直接方式通过滑动在LayerList中定义的项目中加载图像。

虽然你可以通过编程设置drawable来做类似下面的事情。

//Drawable you want to set
Drawable drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.image7, null);
LayerDrawable layerDrawable = (LayerDrawable) ResourcesCompat.getDrawable(getResources(), R.drawable.layer_list, null);
layerDrawable.setDrawableByLayerId(R.id.logo, drawable);
RL.setBackground(layerDrawable);
© www.soinside.com 2019 - 2024. All rights reserved.