android 中图像视图的图像重叠

Image overlapping of image view in android

我有两个圆形图像我想重叠这两个图像但是第二个图像按百分比重叠第一个图像!灰色图像和蓝色图像是两个独立的图像。我想要结果如附图所示。

我在我们的项目中实现了同样的事情。请仔细阅读以下代码段:

XML :

<RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/imagegreenid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:scaleType="fitCenter"
                android:src="@drawable/clip_full_green_gauge" />

            <ImageView
                android:id="@+id/imagewhiteid"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/clip_feil_empty_gauge" />
        </RelativeLayout>

Activity中的代码:

int total_percent = orininalScore * 100;
int TOTAL_VALUE = 10000;

ImageView img = (ImageView) findViewById(R.id.imagegreenid);
ClipDrawable mImageDrawable = (ClipDrawable) img.getDrawable();
mImageDrawable.setLevel(total_percent);
ImageView img1 = (ImageView) findViewById(R.id.imagewhiteid);
ClipDrawable mImageDrawable1 = (ClipDrawable) img1.getDrawable();
mImageDrawable1.setLevel(TOTAL_VALUE - total_percent);

太晚了,但对于历史来说:),我想你可以使用前景和背景属性。确保它们都是 png。

 <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/ic_event_available_black_48dp"
            android:foreground="@drawable/baseline_close_black_36"
            android:foregroundTint="@android:color/holo_red_dark"
        ></ImageView>