gpt4 book ai didi

java - ScaleGestureDetector 不工作不显示任何内容

转载 作者:太空宇宙 更新时间:2023-11-04 11:17:16 25 4
gpt4 key购买 nike

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 i = 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 Up 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>

我有一个 ImageView ,我有图像毕加索库来动态显示图像。我正在使用 ScaleGestureDetector 但不工作任何错误消息请帮助我。没有任何错误,但没有任何反应此代码请帮助我如何解决此问题。请帮助我

最佳答案

onTouchEvent(..)

不是每次都会调用, - 仅当 View 不处理 onTouch 事件时才会调用:您应该使用dispatchTouchEvent(MotionEvent event)

 @Override
public boolean dispatchTouchEvent(MotionEvent event) {
return SDG.onTouchEvent(event);
}

或者你可以实现View.OnTouchListener

注册一个回调,当触摸事件发送到此 View 时调用。

image.setOnTouchListener(this);

并覆盖

   @Override onTouch(View v, MotionEvent event)
public boolean onTouch(View v, MotionEvent event) {
return SDG.onTouchEvent(event);
}

请参阅以下链接以获取更清晰的触摸事件图片

OnTouchEvent not working on child views

关于java - ScaleGestureDetector 不工作不显示任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45321728/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com