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);
}
}
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:
scaling/zooming works but layout is clipped
How can i fix this issue?
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:
Use ViewGroup.layout. It may be the easiest way to scale(&move) ViewGroup.
If I understand your problem correctly, you are scaling a view group and expect the included views to scale accordingly. It doesn't work that way: you scale the view group and it changes size, but its children views do not.
Just scale all subviews. Even so, I am not sure that texts and images are going to be automatically scaled. What you want is zoom, not scale. Try this reference.
The parent of your view must have the property
android:clipChildren
disabled (from layout file or withsetClipChildren(false)
).But with this method you don't get the touch events outside the view clip bounds. You can work around by sending them from your activity or writing a custom
ViewGroup
parent.I'm using a different hack which seems to work in my case, the trick is to maintain your own transformation matrix. Then, you have to overload a lot of
ViewGroup
's method to make it work. For example :Since API Level 11, the
View
class hassetScaleX()
andsetScaleY()
methods, that work as expected and also scale sub-views of the scaled view. So, if that'd be a way for you, drop the library and just do