问题描述
这很容易放大图片和网络的意见。但我想缩放整个活动。我怎样才能做到这一点?
It's easy to zoom images and web views. But I want to zoom a whole activity. How can I do this?
从这里就可以明白,我想要做的。
From this you can understand, what I want to do.
如果您有任何这解决方案,那么请大家分享。
谢谢。
If you have any solution of this, then please share.
Thank you.
推荐答案
您可以模拟放大和缩小通过扩大根系活力观点。下面是一些入门code:
You can simulate zooming in and out by scaling the root activity view. Here's some starter code:
View v = findViewById(android.R.id.content); // get reference to root activity view
v.setOnClickListener(new OnClickListener() {
float zoomFactor = 1.5f;
boolean zoomedOut = false;
@Override
public void onClick(View v) {
if(zoomedOut) {
// now zoom in
v.setScaleX(1);
v.setScaleY(1);
zoomedOut = false;
}
else {
v.setScaleX(zoomFactor);
v.setScaleY(zoomFactor);
zoomedOut = true;
}
}
});
请注意,该活动将放大单点击,而不是在双击缩放。此外,你可能要动画缩放。查找物业动画了解详细信息,如何做到这一点。
Note, the activity will zoom on single clicks as opposed to zooming upon double tap. Also, you probably want to animate the zooming. Look up Property Animation for details how to accomplish this.
对于较旧的API级别,就可以使用ScaleAnimation。您还可以设置动画的持续时间。然而,主要需要注意的是,它只能修改视图的外观,但实际的观点并没有改变。
For older API levels, you can use ScaleAnimation. You can also set the duration of the animation. However, a major caveat is that it only modifies the look of the view, but the actual view doesn't change.
if(zoomedOut) { // zoom in
ScaleAnimation anim = new ScaleAnimation(1f, 1.5f, 1f, 1.5f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(500);
anim.setFillAfter(true);
v.startAnimation(anim);
zoomedOut = false;
}
else {
ScaleAnimation anim = new ScaleAnimation(1.5f, 1f, 1.5f, 1f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
anim.setDuration(500);
anim.setFillAfter(true);
v.startAnimation(anim);
zoomedOut = true;
这篇关于如何放大的多点触摸整个活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!