gpt4 book ai didi

java - 如何分离 TextView 以仅影响一个 TextView ?

转载 作者:行者123 更新时间:2023-12-02 12:37:52 28 4
gpt4 key购买 nike

我正在使用 onTouchEvent 方法来缩放 TextView ,但是当我有两个 TextView 并且我只想调整第一个 TextView 而不是第二个 TextView 时,我遇到了麻烦。我的意思是,我想分别缩放两者。我应该怎么办?

方法

 @Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() == 2) {
int action = event.getAction();
int pureaction = action & MotionEvent.ACTION_MASK;
if (pureaction == MotionEvent.ACTION_POINTER_DOWN) {
mBaseDist = getDistance(event);
mBaseRatio = mRatio;
} else {
float delta = (getDistance(event) - mBaseDist) / STEP;
float multi = (float)Math.pow(2, delta);
mRatio = Math.min(1024.0f, Math.max(0.1f, mBaseRatio * multi));
//Definir aquí el tamaño del texto
textView1.setTextSize(mRatio+13);
textView2.setTextSize(mRatio+13);
}
}
return true;
}

最佳答案

试试这个,

View.OnTouchListener onTouchListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if (event.getPointerCount() == 2) {
int action = event.getAction();
int pureaction = action & MotionEvent.ACTION_MASK;
if (pureaction == MotionEvent.ACTION_POINTER_DOWN) {
mBaseDist = getDistance(event);
mBaseRatio = mRatio;
} else {
float delta = (getDistance(event) - mBaseDist) / STEP;
float multi = (float)Math.pow(2, delta);
mRatio = Math.min(1024.0f, Math.max(0.1f, mBaseRatio * multi));
((TextView)view).setTextSize(mRatio+13);
//Definir aquí el tamaño del texto
//textView1.setTextSize(mRatio+13);
//textView2.setTextSize(mRatio+13);
}
}
return true;
});
textView1.setOnTouchListener(onTouchListener );
textView2.setOnTouchListener(onTouchListener );

它将分别缩放两个 Textview。

关于java - 如何分离 TextView 以仅影响一个 TextView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45079200/

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