Android Imitation English Fluent speaking the realization method of amplification control (with demo source download) _android

Source: Internet
Author: User

An example of this article is the implementation of the Android imitation English fluent word amplification control system. Share to everyone for your reference, specific as follows:

1 Word Amplification control

Fluent English is a very helpful oral learning app, in the app's cultivation page, a long press screen, will pop a magnifying glass, when the finger moved to a word near, you can see that the English word will be selected, the effect of the following image:

2 code example

The control is very interesting, so I wrote a simple demo, complete example code click here to download the site. , the effect of the program after running is as follows:

3 Principle of implementation

The implementation principle of the control is relatively simple, here are some of the more important classes

①wordview

In the process of practicing the control, I found that seemingly ordinary textview, its function is unusually powerful, TextView source is worth studying. The main function of Wordview is to select a word near it according to the touch location, and then change the color of the selected word, the key code is as follows:

public void Tryselectword (Motionevent event) {
  Layout Layout = GetLayout ();
  if (layout = = null) {return
    ;
  }
  int line = layout.getlineforvertical (getscrolly () + (int) event.gety ());
  Final int index = Layout.getoffsetforhorizontal (line, (int) event.getx ());
  Word Selectedword = Getword (index);
  if (Selectedword!= null) {
    Mspannablestring.setspan (Mforegroundcolorspan,
        Selectedword.getstart (), Selectedword.getend (), spanned.span_exclusive_exclusive);
    SetText (mspannablestring);
    Mselectedword = GetText (). Subsequence (Selectedword.getstart (), Selectedword.getend ()). ToString ();
    Monwordselectlistener.onwordselect ();
  }


②exercisepanel

The control is mainly used to display Magnifier, the principle is relatively simple, do not introduce.

For more information on Android-related content readers can view the site topics: "Android Resource Operation tips Summary", "Android Development introduction and Advanced Course", "Android Control Usage Summary", "Android SMS and telephone operating skills summary" and " Android Multimedia How-to Summary (audio, video, recording, etc.)

I hope this article will help you with the Android program.

Related Article

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.