问题描述
我使用 NineOldAndroids 库扩展我的自定义布局。
I use NineOldAndroids library to scale my custom layout.
public class MyLayout extends FrameLayout {
// LayoutParams.MATCH_PARENT and all.
...
@Override
public boolean setPositionAndScale(ViewGroup v, PositionAndScale pas, PointInfo pi) {
...
mScale = pas.getScale();
ViewHelper.setScaleX(this, mScale);
ViewHelper.setScaleY(this, mScale);
}
}
我已经试过的FrameLayout和AbsoluteLayout。所有有同样的效果。当 mScale< 1.0
缩放/缩放作品但布局的一部分,是剪切。
I have tried FrameLayout and AbsoluteLayout. All have the same effect.When mScale < 1.0
scaling/zooming works but part of the layout is clipped.
mScale = 1.0:
mScale = 1.0:
mScale&LT; 1.0:
缩放/缩放作品,但布局的剪切
mScale < 1.0:
scaling/zooming works but layout is clipped
我该如何解决这个问题?
How can i fix this issue?
修改:在这张照片拍摄于ICS。因此,我不认为这是NineOldAndroids问题。
Edit: The picture was taken on ICS. So I don't think it's NineOldAndroids problem.
推荐答案
如果任何人有到一样的情况我。最后我用这种方式:
In case anyone got in to the same situation as me.I ended up using this approach:
protected void setScale(float scale, boolean updateView) {
mScale = scale;
if (updateView) {
LayoutParams params = getLayoutParams();
onUpdateScale(scale, params);
setLayoutParams(params);
}
}
protected void onUpdateScale(float scale, LayoutParams params) {
params.leftMargin = (int) (mModel.getX() * scale);
params.topMargin = (int) (mModel.getY() * scale);
params.width = (int) (mModel.getWidth() * scale);
params.height = (int) (mModel.getHeight() * scale);
}
这篇关于安卓ViewGroup.setScaleX()导致视图被裁剪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!