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.