[英]Android fill color in transparent image
i am working on Image fill color . 我正在处理图像填充颜色。 i have a Transparent image , i need to fill color in image according to percentage of level complete , i don't have idea how to do it , can any one suggest me.
我有一个透明的图像,我需要根据完成水平的百分比在图像中填充颜色,我不知道该怎么做,任何人都可以建议我。
thanks in advance 提前致谢
thanks for help i just did in simple way , i am adjusting hight in run time of first imageview . 谢谢我的简单帮助,我正在调整第一幅imageview的运行时间。
android:layout_width="300dp"
android:layout_centerHorizontal="true"
android:layout_height="300dp"
>
<ImageView
android:id="@+id/view"
android:layout_width="300dp"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:scaleType="fitXY"
android:layout_height="150dp"
/>
<ImageView
android:id="@+id/imgVie"
android:layout_width="300dp"
android:layout_centerHorizontal="true"
android:src="@drawable/masking"
android:scaleType="fitXY"
android:layout_height="300dp"
/>
If you want to play with the opacity of your image, you are looking for the alpha parameter ! 如果要使用图像的不透明度,请寻找alpha参数!
yourImageView.setAlpha(0.5) // alpha is between 0 and 1 (fully transparent/opaque)
If you want to change the color of your image, you'll have to work with ColorMatrixFilter : 如果要更改图像的颜色,则必须使用ColorMatrixFilter:
ColorMatrix myColorMatrix = new ColorMatrix(new float[]{
1,0,0,RGBValR, //red value
0,1,0,RGBValG,
0,0,1,RGBValB,
0,0,0,1});
ColorMatrixColorFilter myFilter = new ColorMatrixColorFilter(myColorMatrix);
myImageView.setColorFilter(myfilter);
To set background color for a transparent image, backgroundTint
attribute can be used. 要为透明图像设置背景颜色,可以使用
backgroundTint
属性。
<android.support.v7.widget.AppCompatImageView
android:layout_width="30dp"
android:layout_height="30dp"
android:background="@drawable/ic_star_white"
android:backgroundTint="@color/colorPrimary" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.