我一直在尝试获得如下想要的结果,但没有成功。我需要将图像视图屏蔽为文本,以便图像视图看起来像文本,但仍然作为图像视图工作,以便我可以在其中使用缩放功能。
图像不应溢出到文本边框之外。我有滑翔变换和其他一些,但它没有锻炼。文本是动态的,可以用任何字母或单词替换。
编辑
这是一个代码片段:
Glide.with(this).load(R.drawable.eagle).override(width, height).bitmapTransform(new CenterCrop(this),
new MaskTransformation(mContext, R.drawable.mask_e)).into(Imageview);
// 1. find your need text`enter code here`view
val tv = findViewById<TextView>(R.id.text)
// 2. generate bitmap your need image (like be drawable resource)
val mask = BitmapFactory.decodeResource(resources, R.drawable.bg)
// 3. create shader
val shader = BitmapShader(mask, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT)
// 4. set shader to text view
tv.paint.shader = shader
要将文本添加到 ImageView,您可以执行以下操作:
<RelativeLayout>
<ImageView
android:id="@+id/myImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/myImageSouce" />
<TextView
android:id="@+id/myImageViewText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/myImageView"
android:layout_alignTop="@+id/myImageView"
android:layout_alignRight="@+id/myImageView"
android:layout_alignBottom="@+id/myImageView"
android:layout_margin="1dp"
android:gravity="center"
android:text="Hello"
android:textColor="#000000" />
</RelativeLayout>
PS。仅适用于relativelayout