Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

zoom textview having image and text(Html content) in android

I have a textview having html content with both images and text. I have to zoom the textview. I know how to zoom the text in the textview. But the image will not be zoomed by this.

textview.setText(Html.fromHtml("text",
            new ImageGetter(), null));

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));
            textview.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;
}

How can I zoom both image and text on this textview

like image 246
Ameer Avatar asked Nov 11 '22 13:11

Ameer


1 Answers

I solved my problem by using WebViewinstead of TextView

    final String mimeType = "text/html";
    final String encoding = "UTF-8";
    webView.loadDataWithBaseURL("", textview, mimeType,
            encoding, "");
    webView.getSettings().setBuiltInZoomControls(true);
like image 168
Ameer Avatar answered Nov 14 '22 21:11

Ameer