Gesture Scaling (1), gesture Scaling (

Source: Internet
Author: User
Tags gety

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



}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.