Gesture Scaling (1), gesture Scaling (
Effect: font Scaling (countless times). At present, I have a custom multiple, but it is a bit of a BUG, and the scroollveiw sliding conflict is not solved;
1. activity_main.xml
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="11sp"
android:scrollbars="vertical"
/>
</ScrollView>
2. MainActivity. java
TextView textView = (TextView) findViewById (R. id. textView );
TextView. setMovementMethod (ScrollingMovementMethod. getInstance ());
TextView. setText ("three emperors and Five Emperors of morality, \ n" + "Shang Zhou. \ n" + "Heroes and five overlord in spring and autumn, \ n" + "success and death. \ n"
+ "The last names of several qingshi lines, \ n" + "countless barren hills in Beibei District. \ n "+" future generations from the previous field accept, \ n "+" Let's talk about the fight. "+" moral emperor, \ n "+" after the summer. \ n "+" Hero five overlord in the spring and autumn, \ n "+" instantly lost. \ n"
+ "The last names of several qingshi lines, \ n" + "countless barren hills in Beibei District. \ n "+" future generations from the previous field accept, \ n "+" Let's talk about the fight. "+" moral emperor, \ n "+" after the summer. \ n "+" Hero five overlord in the spring and autumn, \ n "+" instantly lost. \ n"
+ "The last names of several qingshi lines, \ n" + "countless barren hills in Beibei District. \ n "+" future generations from the previous field accept, \ n "+" Let's talk about the fight. "+" moral emperor, \ n "+" after the summer. \ n "+" Hero five overlord in the spring and autumn, \ n "+" instantly lost. \ n"
+ "The last names of several qingshi lines, \ n" + "countless barren hills in Beibei District. \ n "+" future generations from the previous field accept, \ n "+" Let's talk about the fight. "+" moral emperor, \ n "+" after the summer. \ n "+" Hero five overlord in the spring and autumn, \ n "+" instantly lost. \ n"
+ "The last names of several qingshi lines, \ n" + "countless barren hills in Beibei District. \ n "+" future generations from the previous field accept, \ n "+" Let's talk about the fight. "+" moral emperor, \ n "+" after the summer. \ n "+" Hero five overlord in the spring and autumn, \ n "+" instantly lost. \ n"
+ "The last names of several qingshi lines, \ n" + "countless barren hills in Beibei District. \ n "+" future generations from the previous field accept, \ n "+" Let's talk about the fight. "+" moral emperor, \ n "+" after the summer. \ n "+" Hero five overlord in the spring and autumn, \ n "+" instantly lost. \ n"
+ "The last names of several qingshi lines, \ n" + "countless barren hills in Beibei District. \ n "+" future generations from the previous field accept, \ n "+" Let's talk about the fight. "+" moral emperor, \ n "+" after the summer. \ n "+" Hero five overlord in the spring and autumn, \ n "+" instantly lost. \ n"
+ "The last names of several qingshi lines, \ n" + "countless barren hills in Beibei District. \ n" + "the future generations of the previous field accept, \ n" + "let's say that they are fighting together .");
TextView. getParent (). requestDisallowInterceptTouchEvent (true );
TextView. setOnTouchListener (new ZoomListenter ());
3. ZoomListenter. java
Import android. view. MotionEvent;
Import android. view. View;
Import android. view. View. OnTouchListener;
Import android. widget. TextView;
Public class ZoomListenter implements OnTouchListener {
Private int mode = 0;
Float oldDist;
Float textSize = 0;
TextView textView;
Final static float defaultTextSize = 11.0f;
Public boolean onTouch (View v, MotionEvent event ){
TextView = (TextView) v;
If (textSize = 0 ){
TextSize = textView. getTextSize ();
}
Switch (event. getAction () & MotionEvent. ACTION_MASK ){
Case MotionEvent. ACTION_DOWN:
Mode = 1;
Break;
Case MotionEvent. ACTION_UP:
Mode = 0;
Break;
Case MotionEvent. ACTION_POINTER_UP:
Mode-= 1;
Break;
Case MotionEvent. ACTION_POINTER_DOWN:
OldDist = spacing (event );
Mode + = 1;
Break;
Case MotionEvent. ACTION_MOVE:
If (mode> = 2 ){
Float newDist = spacing (event );
If (newDist> oldDist + 1 ){
If (textSize <defaultTextSize * 3 ){
Zoom (newDist/oldDist );
OldDist = newDist;
}
}
If (newDist <oldDist-1 ){
If (textSize> defaultTextSize ){
Zoom (newDist/oldDist );
OldDist = newDist;
}
}
}
Break;
}
Return true;
}
Private void zoom (float f ){
TextView. setTextSize (textSize * = f );
}
Private float spacing (MotionEvent event ){
Float x = event. getX (0)-event. getX (1 );
Float y = event. getY (0)-event. getY (1 );
// Square root
Return (float) Math. sqrt (x * x + y * y );
}
}