使用OnTouchListener和setMovementMethod的Textview

时间:2014-02-08 06:26:09

标签: android textview

我有一个包含html内容的textview,我必须缩放textview并且还需要使用setMovementMethod。但是如果将setMovementMethod应用于textView,则OnTouchListener无法正常工作 我为textView尝试了setFocusable(boolean)但没有工作。 以下是我的代码

        contentTextView.setText(Html.fromHtml(contentToShowString,
            new ImageGetter(), null));

    contentTextView.setMovementMethod(LinkMovementMethod.getInstance());

private class ImageGetter implements Html.ImageGetter {

    public Drawable getDrawable(String source) {
        LevelListDrawable d = new LevelListDrawable();
        Drawable empty = getResources().getDrawable(R.drawable.ic_launcher);
        d.addLevel(0, 0, empty);
        d.setBounds(0, 0, empty.getIntrinsicWidth(),
                empty.getIntrinsicHeight());

        new LoadImage().execute(source, d);

        return d;
    }
};

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));
            contentTextView.setTextSize(mRatio + 13);
        }
    }
    return true;
}

int getDistance(MotionEvent event) {
    int dx = (int) (event.getX(0) - event.getX(1));
    int dy = (int) (event.getY(0) - event.getY(1));
    return (int) (Math.sqrt(dx * dx + dy * dy));
}

public boolean onTouch(View v, MotionEvent event) {

    return false;
}

0 个答案:

没有答案