简体   繁体   中英

How can i separate textviews to affect only one textview?

I am using onTouchEvent method to scale textview, but i am getting trouble when i have two textviews and i only want to resize the first one and not the second one. I mean, i want to scale both separately. What should i do?

Method

 @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;
    }

Try this,

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 );

It will scale both Textview separately.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM