gpt4 book ai didi

java - setMovementMethod(滚动)干扰 textView 中的 scaleGestureDetector(缩放)

转载 作者:行者123 更新时间:2023-11-29 21:26:52 25 4
gpt4 key购买 nike

非常感谢您的阅读。我有一个可以缩放的 textView,当我将 "textview.setMovementMethod(new ScrollingMovementMethod());" 添加到我的代码时,我还可以滚动缩放的 textview,这正是我所需要的。问题是一旦文本被缩放,只有滚动有效,但捏合缩放不再有效,(除非我将一根手指放在 TextView 外,另一根手指放在 TextView 内)。任何帮助将不胜感激。我从这里得到代码:Pinch Zooming TextView

import android.os.Bundle;
import android.app.Activity;
import android.util.Log;
import android.util.TypedValue;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.ScaleGestureDetector;
import android.view.ScaleGestureDetector.SimpleOnScaleGestureListener;
import android.widget.TextView;

public class MainActivity extends Activity {

TextView scaleGesture;
ScaleGestureDetector scaleGestureDetector;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scaleGesture = (TextView)findViewById(R.id.article);
scaleGesture.setText("this is some text");
scaleGestureDetector = new ScaleGestureDetector(this, new simpleOnScaleGestureListener());
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}


@Override
public boolean onTouchEvent(MotionEvent event) {
// TODO Auto-generated method stub
scaleGestureDetector.onTouchEvent(event);
return true;
}

public class simpleOnScaleGestureListener extends
SimpleOnScaleGestureListener {

@Override
public boolean onScale(ScaleGestureDetector detector) {
// TODO Auto-generated method stub
float size = scaleGesture.getTextSize();
Log.d("TextSizeStart", String.valueOf(size));

float factor = detector.getScaleFactor();
Log.d("Factor", String.valueOf(factor));


float product = size*factor;
Log.d("TextSize", String.valueOf(product));
scaleGesture.setTextSize(TypedValue.COMPLEX_UNIT_PX, product);

size = scaleGesture.getTextSize();
Log.d("TextSizeEnd", String.valueOf(size));
return true;
}
}
}`

最佳答案

我只是解决这个问题(同一个例子)只在我的代码中添加一个“如果”:

    @Override
public boolean onTouchEvent(MotionEvent event) {
// get how many fingers is in touch (in that case, if are more
// than 1, the user don't want do the scroll
if (event.getPointerCount() > 1) {
scaleGestureDetector.onTouchEvent(event);
return true;
}
return false;
}

关于java - setMovementMethod(滚动)干扰 textView 中的 scaleGestureDetector(缩放),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20139493/

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