Android:镜像视图 [英] Android: Mirroring a View

查看:100
本文介绍了Android:镜像视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个需要垂直翻转或镜像的视图.如

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?

推荐答案

您可以简单地创建

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆