image - how to move an imageview to right get activity in android? -
i have implemented application image view in application implement when user move image right side next acitvity. how can write event or other code move image right side?
i have used imageview code as:
(imageview)findviewbyid(r.id.slide) //event move right here intent = new intent(slide.this,nextactivity.class); startactivity(it);
please body me...
so, if understood correctly, want move imageview across screen, drag it, , when hit spot want start activity?
if so, try , use code below...which let's drag imageview across screen
just add ontouchlistener imageview you're trying slide (move/drag)
yourslideimageviewobject.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { onslidetouch(v, event); return false; } });
then add code handle touch events
public void onslidetouch( view view, motionevent event ) { //when user pushes down on imageview if ( event.getaction() == motionevent.action_down ) { indragmode = true; //set variable know started draggin imageview //set selected imageview x , y exact position selectedimageviewx = math.abs((int)event.getrawx()-((imageview)view).getleft()); selectedimageviewy = math.abs((int)event.getrawy()-((imageview)view).gettop()); //bring imageview in front ((imageview)view).bringtofront(); } //when user let's imageview go (raises finger) if ( event.getaction() == motionevent.action_up ) { indragmode = false; //reset variable let's know we're not in drag mode anymore } //when user keeps finger on te screen , drags (slides it) if ( event.getaction() == motionevent.action_move ) { //if we've started draggin imageview if ( indragmode ) { //get imageview object imageview slide = (imageview)findviewbyid(r.id.slide); //get parameters object (this example relative layout) relativelayout.layoutparams params = relativelayout.layoutparams)slide.getlayoutparams(); //change position of imageview accordingly params.setmargins((int)event.getrawx()-selectedimageviewx, (int)event.getrawy()-selectedimageviewy, 0, 0); //set new params slide.setlayoutparams(params); //if hit limit our imageview position if( slideimageview_position inside interval ) { //open activity intent = new intent(slide.this,nextactivity.class); startactivity(it); } } } }
the above should drag imageview accross screen.
you can implement in motionevent.action_move event .... limit movement of imageview accross screen. check new coordinates of finger across screen , check if out of bounds. if so, nothing. if aren't out of bounds, change left , upper margins of imaveview.
also, on motionevent.action_up event, check see if left margin of imaveview on predefined limit (which means user slided imageview on intended position). if so, can continue doing whatever want, means starting activity. or, if don't want open activity while user dragging, not after has removed finger imageview, if () i've written under motionevent.action_move event. insert there interval want, when imageview dragged inside interval, activity starts.
if you're confused, please ask :) it's late here, , i'm tired, might have not explained :d
Comments
Post a Comment