android - Get X and y Coordinates of child view of relative layout pinch zoom? -
android - Get X and y Coordinates of child view of relative layout pinch zoom? -
// here xml
<com.example.zoomrelative.zoomablerelativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/rlcontainer" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.zoomrelative.mainactivity$placeholderfragment" > <imageview android:id="@+id/image" android:layout_width="wrap_content" android:contentdescription="@string/app_name" android:layout_height="wrap_content" android:layout_centerinparent="true" android:background="@drawable/ic_launcher" /> </com.example.zoomrelative.zoomablerelativelayout>
// java code
public class mainactivity extends actionbaractivity { private zoomablerelativelayout rlcontainer; private scalegesturedetector scalegesturedetector; private imageview image; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); image = (imageview) findviewbyid(r.id.image); rlcontainer = (zoomablerelativelayout) findviewbyid(r.id.rlcontainer); //gesture listener scalegesturedetector = new scalegesturedetector(this, new onpinchlistener()); rlcontainer.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { scalegesturedetector.ontouchevent(event); homecoming true; } }); } // pinch zoom on view private class onpinchlistener extends simpleonscalegesturelistener { float startingspan; float startfocusx; float startfocusy; public boolean onscalebegin(scalegesturedetector detector) { startingspan = detector.getcurrentspan(); startfocusx = detector.getfocusx(); startfocusy = detector.getfocusy(); homecoming true; } @suppresslint("newapi") public boolean onscale(scalegesturedetector detector) { rlcontainer.scale(detector.getcurrentspan() / startingspan, startfocusx, startfocusy); rlcontainer.requestfocus(); image.requestfocus(); int[] posxy = new int[2]; image.getlocationonscreen(posxy); int x = posxy[0]; int y = posxy[1]; log.e("x-y", x + " - " + y); homecoming true; } public void onscaleend(scalegesturedetector detector) { //rlcontainer.restore(); } } }
// here have used above code, getting same x , y coordinates on pinch zoom, want within imageview's current x , y co ordinates.please provide me solution if have. thanks.
android coordinates pinchzoom
Comments
Post a Comment