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
I solved my problem by using WebView
instead of TextView
final String mimeType = "text/html";
final String encoding = "UTF-8";
webView.loadDataWithBaseURL("", textview, mimeType,
encoding, "");
webView.getSettings().setBuiltInZoomControls(true);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With