java - ScaleGestureDetector Not Working Not showing Anything -


fulloffer.java

package com.synergywebdesigners.veebee;  import android.content.intent; import android.graphics.matrix; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.text.html; import android.view.motionevent; import android.view.scalegesturedetector; import android.widget.imageview; import android.widget.textview; import android.widget.toast;  import com.squareup.picasso.picasso;  public class fulloffer extends appcompatactivity {     imageview image;     textview start,end,title,messages;     float scale = 1f;     scalegesturedetector sdg;     @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.activity_full_offer);         start = (textview) findviewbyid(r.id.start);         end = (textview) findviewbyid(r.id.end);         title = (textview) findviewbyid(r.id.title);         messages = (textview) findviewbyid(r.id.message);         image = (imageview) findviewbyid(r.id.imagedownloaded);          intent = getintent();         settitle(i.getstringextra("title"));//title of application         start.settext(i.getstringextra("start"));         end.settext(i.getstringextra("end"));         title.settext(i.getstringextra("title"));         messages.settext(html.fromhtml(i.getstringextra("message")),textview.buffertype.spannable);         picasso.with(fulloffer.this).load(config.upload_location+i.getstringextra("image")).fit().into(image);         sdg = new scalegesturedetector(this,new scalelistner());     }     @override     public boolean ontouchevent(motionevent event) {         sdg.ontouchevent(event);        /* return true;*/         return super.ontouchevent(event);     }     private class scalelistner extends scalegesturedetector.simpleonscalegesturelistener{        float onscalebegin = 0;         float onscaleend = 0;         @override         public boolean onscale(scalegesturedetector detector) {            /* scale = scale * detector.getscalefactor();             scale = math.max(0.1f,math.min(scale,5f));             matrix.setscale(scale,scale);             image.setimagematrix(matrix);*/            scale *= detector.getscalefactor();             image.setscalex(scale);             image.setscaley(scale);             return true;         }         @override         public boolean onscalebegin(scalegesturedetector detector) {             toast.maketext(getapplicationcontext(), "your application pinch" ,toast.length_short).show();             onscalebegin = scale;             return true;         }          @override         public void onscaleend(scalegesturedetector detector) {            onscaleend = scale;             if(onscaleend > onscalebegin){                 toast.maketext(getapplicationcontext(),"scaled by"+string.valueof(onscaleend/onscalebegin),toast.length_short).show();             }else if(onscaleend<onscalebegin){                 toast.maketext(getapplicationcontext(),"scaled down by"+string.valueof(onscaleend/onscalebegin),toast.length_short).show();             }         }     }   } 

activity_full_offer.xml

<?xml version="1.0" encoding="utf-8"?> <scrollview xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:layout_marginleft="2dp"     android:layout_marginright="2dp"     android:scrollbars="none"     android:background="#ffffff"     tools:context="com.synergywebdesigners.veebee.fulloffer">     <linearlayout         android:orientation="vertical"         android:layout_width="match_parent"         android:layout_height="match_parent">         <imageview android:id="@+id/imagedownloaded"             android:layout_width="match_parent"             android:layout_height="400dp"             android:src="@drawable/abc_ic_menu_copy_mtrl_am_alpha"/>         <!-- title label -->         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="new text"             android:textallcaps="true"             android:textappearance="?android:attr/textappearancemedium"             android:textcolor="#000000"             android:textstyle="bold"             android:id="@+id/title"             android:gravity="center"/>         <textview             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:text="new text"             android:id="@+id/message"             android:layout_marginleft="20dp"             android:layout_marginright="10dp"             android:layout_margintop="10dp"/>         <linearlayout             android:layout_width="match_parent"             android:layout_height="wrap_content"             android:background="#eff0f1"             android:orientation="horizontal">             <linearlayout                 android:layout_width="wrap_content"                 android:layout_height="wrap_content"                 android:orientation="horizontal">                 <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:textstyle="bold"                     android:text="start date :"/>                 <textview                     android:id="@+id/start"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_marginleft="5dp"                     android:text="20-07-2017"/>             </linearlayout>             <linearlayout                 android:layout_width="match_parent"                 android:layout_height="wrap_content"                 android:gravity="right"                 android:orientation="horizontal">                 <textview                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:textstyle="bold"                     android:text="valid till :"/>                 <textview                     android:id="@+id/end"                     android:layout_width="wrap_content"                     android:layout_height="wrap_content"                     android:layout_marginleft="5dp"                     android:text="22-07-2017"/>             </linearlayout>         </linearlayout>      </linearlayout> 

i have image view have image picasso library showing image dynamically . use scalegesturedetector not working no error message come please me . no error come nothing happen code please me how can fix issue. please me

ontouchevent(..)

is not called everytime, - gets called if views not handle ontouch event: should use dispatchtouchevent(motionevent event)

 @override     public boolean dispatchtouchevent(motionevent event) {         return sdg.ontouchevent(event);     } 

or else can implement view.ontouchlistener

register callback invoked when touch event sent view.

image.setontouchlistener(this); 

and override

   @override ontouch(view v, motionevent event)     public boolean ontouch(view v, motionevent event) {         return sdg.ontouchevent(event);     } 

refer follwing link more clear picture of touch events

ontouchevent not working on child views


Comments

Popular posts from this blog

python - Selenium remoteWebDriver (& SauceLabs) Firefox moseMoveTo action exception -

html - How to custom Bootstrap grid height? -

transpose - Maple isnt executing function but prints function term -