Android:镜像视图 [英] Android: Mirroring a View
问题描述
I have a view I need to flip vertically, or mirror. There's plenty of information out there about mirroring a single bitmap by scaling it by -1 and translating for the offset, as described here, but there doesn't seem to be any information on how to draw all the contents of a View - specifically, all of it's subviews - upside down.
我在此容器中有多个子视图-文本,图像-我希望有一种方法可以让我将它们添加到单个视图中,然后上下颠倒绘制该视图,而不是让它们全部执行自定义绘制代码以将它们上下颠倒,并使容器将它们重新适当定位.有什么想法吗?
I have multiple subviews in this container - text, images - and I was hoping for a way that would let me just add them to a single View and draw that View upside down/sideways, rather than having them all perform custom drawing code to draw them upside down and have the container reposition them all appropriately. Any ideas?
推荐答案
您可以简单地创建 View.draw(Canvas)
方法.这将为您提供Bitmap
中视图层次结构的快照.然后,您可以应用上述转换来镜像图像.
You could simply create a Canvas
out of a Bitmap
and then invoke your root view's View.draw(Canvas)
method. This will give you a snapshot of the view hierarchy in a Bitmap
. You then apply the aforementioned transformations to mirror the image.
这篇关于Android:镜像视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!