2013年9月22日星期日

android how to achieve the view zoom in and out

Recently made a display list feature, because the interface you want to display a lot of data , so the data may look seem a small point, but now need to do is , when I point when it enlarged buttons , you can whole person view zoom effect, can see more clearly the data ;

need to achieve is a view of the overall amplification is an enlarged view of the picture is not enlarged Kazakhstan , experts advise ..
------ Solution - ------------------------------------------
you view initialization when there is a setLayoutParams not control it to change attributes Well , maybe a little stupid
------ Solution ---------------- ----------------------------
landlord, you android mobile platform in the forum to hair thing.
------ For reference only -------------------------------------- -
not the case, this view is already initialized completed , the data is written , is itself a view, I now need to do is go now view on the basis of this view ... enlarge
------ For reference only ---------------------------------- -----
ah just did not find
------ For reference only ----------------------- ----------------
landlord what your problem solved ?

personally feel like pure hard A pair of upper api app yet know , do not know whether there are other ways
------ For reference only ------------ ---------------------------
this question can not be considered completely solved, can only be a partial solution ;
Workaround : Customize the amplification factor a linearlayout pass it , rewrite drow way , matix to control zoom ;
multi-touch ; so basically can be achieved on view enlarged ; I realized some functions . Is feasible ,
------ For reference only ---------------------------------- -----
specific code can be passed about what
------ For reference only ----------------------- ----------------
Hello , is there DEMO stickers to let everyone learn from ah ? ?
------ For reference only -------------------------------------- -
/ / zoom view
public class ScaleGesture implements OnScaleGestureListener {

private float beforeFactor;
private float mPivotX;
private float mPivotY;
private View mVSouce;
private boolean isFillAfter;

public void setSourceView (View destinyView) {
mVSouce = destinyView;
}

@ Override
public boolean onScale (ScaleGestureDetector detector) {
if (checkIsNull ()) {
return false;
}
final float factor = detector.getScaleFactor ();
Animation animation = new ScaleAnimation (beforeFactor, factor,
beforeFactor, factor, mPivotX, mPivotY);
animation.setFillAfter (true);
mVSouce.startAnimation (animation);
beforeFactor = factor;
return false;
}

@ Override
public boolean onScaleBegin (ScaleGestureDetector detector) {
if (checkIsNull ()) {
return false;
}
beforeFactor = 1f;
mPivotX = detector.getFocusX () - mVSouce.getLeft ();
mPivotY = mVSouce.getTop () + (mVSouce.getHeight () >> 1);
return true;
}

@ Override
public void onScaleEnd (ScaleGestureDetector detector) {
if (checkIsNull ()) {
return;
}
final float factor = detector.getScaleFactor ();
final int nWidth = (int) (mVSouce.getWidth () * factor);
final int nHeight = (int) mVSouce.getHeight ();
final int nLeft = (int) (mVSouce.getLeft () - ((nWidth - mVSouce
. getWidth ()) * (mPivotX / mVSouce.getWidth ())));
final int nTop = (int) mVSouce.getTop ();
if (isFillAfter) {
mVSouce.layout (nLeft, nTop, nLeft + nWidth, nTop + nHeight);
}
/ / MUST BE CLEAR ANIMATION. OTHERWISE WILL BE FLICKER
/ / if can not clear animation the layout will keep the size
/ / mVSouce.clearAnimation ();
}

public boolean checkIsNull () {
return mVSouce == null? true: false;
}

/ **
* if parameter is true that keeping same scale when next scaling.
*
* @ param isFill
* /
public void setFillAfter (boolean isFill) {
isFillAfter = isFill;
}
}
/ * define variables inside the activity * /
ScaleGesture sg = new ScaleGesture ();
ScaleGestureDetector detector;
/ * inside * the oncreat method /
detector = new ScaleGestureDetector ( you have to zoom view.getContext (), sg);
sg.setSourceView ( you have to zoom view);
/ * can zoom, but the mobile view to achieve good, you can use scrollby enables mobile view * /

没有评论:

发表评论