java - How to implement 3d effect zooming in viewpager android -
i need regarding viewpager. have viewpager contained in page container:
package com.example.customviews; /** * created imrankhan on 4/29/2015. */ import android.content.context; import android.graphics.camera; import android.graphics.matrix; import android.graphics.point; import android.support.v4.view.viewpager; import android.util.attributeset; import android.view.motionevent; import android.view.view; import android.view.animation.animation; import android.view.animation.animationutils; import android.view.animation.transformation; import android.widget.framelayout; import android.widget.imageview; import com.example.imrankhan.newlawdojo.dashboardactivity; import com.example.imrankhan.newlawdojo.quizactivity; import com.example.imrankhan.newlawdojo.r; /** * pagercontainer: layout displays viewpager children outside * typical pager bounds. */ public class pagecontainer extends framelayout implements viewpager.onpagechangelistener { private viewpager mpager; boolean mneedsredraw = false; private camera mcamera = new camera(); private int mmaxrotationangle = 60; private int mmaxzoom = -120; public pagecontainer(context context) { super(context); init(); } public pagecontainer(context context, attributeset attrs) { super(context, attrs); init(); } public pagecontainer(context context, attributeset attrs, int defstyle) { super(context, attrs, defstyle); init(); } private void init() { //disable clipping of children non-selected pages visible setclipchildren(false); //child clipping doesn't work hardware acceleration in android 3.x/4.x //you need set value here if using hardware acceleration in // application targeted @ these releases. setlayertype(view.layer_type_software, null); } @override protected void onfinishinflate() { try { mpager = (viewpager) getchildat(0); mpager.setonpagechangelistener(this); } catch (exception e) { throw new illegalstateexception("the root child of pagercontainer must viewpager"); } } public viewpager getviewpager() { return mpager; } private point mcenter = new point(); private point minitialtouch = new point(); @override protected void onsizechanged(int w, int h, int oldw, int oldh) { mcenter.x = w / 4; mcenter.y = h / 4; } @override public boolean ontouchevent(motionevent ev) { //we capture touches not handled viewpager // implement scrolling touch outside pager bounds. switch (ev.getaction()) { case motionevent.action_down: minitialtouch.x = (int)ev.getx(); minitialtouch.y = (int)ev.gety(); default: ev.offsetlocation(mcenter.x - minitialtouch.x, mcenter.y - minitialtouch.y); break; } return mpager.dispatchtouchevent(ev); } @override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { //force container redraw on scrolling. //without outer pages render , stay static if (mneedsredraw) invalidate(); } @override public void onpageselected(int position) { view v =this.getviewpager().getchildat(position); } private void transformimagebitmap(view child, transformation t, int rotationangle) { mcamera.save(); final matrix imagematrix = t.getmatrix();; final int imageheight = child.getlayoutparams().height;; final int imagewidth = child.getlayoutparams().width; final int rotation = math.abs(rotationangle); mcamera.translate(0.0f, 0.0f, 100.0f); if ( rotation < mmaxrotationangle ) { float zoomamount = (float) (mmaxzoom + (rotation * 1.5)); mcamera.translate(0.0f, 0.0f, zoomamount); } mcamera.rotatey(rotationangle); mcamera.getmatrix(imagematrix); imagematrix.pretranslate(-(imagewidth/2), -(imageheight/2)); imagematrix.posttranslate((imagewidth/2), (imageheight/2)); mcamera.restore(); } @override public void onpagescrollstatechanged(int state) { mneedsredraw = (state != viewpager.scroll_state_idle); } }
on onpageselected
event got view need zoom in when selected , zoom out after selecting item. please me out. added image give idea want.
Comments
Post a Comment