Question

We developing custom textview that zoom in/out depends on pinch gesture, and able to resize textview and scale text. But, when zoom out this view, text are cropped unintentionally.

We write a code like this.

1.Get scaled value in gesture listener and postScale in onDraw()

2.Calculate new view size by layout(int, int, int, int)

    @Override
public void onDraw(Canvas canvas) {         

    android.graphics.Matrix m = new android.graphics.Matrix();          
    m.postScale(mScaleFactor, mScaleFactor);    
    canvas.concat(m);
    layout((int) l, (int) t, (int)r , (int) b );

    super.onDraw(canvas);
}
Was it helpful?

Solution

This is may not be perfect solution for you,But you can try it.

1)Detect the pinch gesture

2)calculate the Scale factor(you can do it manually or you can use ScaleDetector class)

3)Use LayoutParams to actually resize your textview.

4)however it will not scale the text size but you can do it programatically respective to your scale gesture.

If you have any question feel free to comment,I have done it before with slightly different requirement.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top