The Apeendtextview of Android_youtharea

Source: Internet
Author: User

This time, give me an ad for my own project: http://sj.qq.com/myapp/detail.htm?apkName=com.youthcommunity

This app is different from Sohot is positive, is the information and story of young people other tech news and so on ...
I hope you will support ... Let's assume that the post-effect will allow me to keep this series of blogs going.
Analyze from the boot page. and finally open source

Let's start with a first page effect.

This time bring in the first time that the word display of the small control to call him Appendtextview it,

* Realization Ideas

1, apart first write a view inheritance TextView
2. Write your own definition properties
3, initialize your own definition properties
4, a thread used to set the time interval TextView text
5, set a text end listener for todo something ....

OK analysis completed. Let's finish this little thing.

Let's take a look at yourself. Defining attributes

Just one is we need to show the text, pay attention to use when not written text= "xxxx"
That would be a normal textview.

Our Attrs file, super simple on one property

And then there are some of the important variables of our Appendtextview
One is for the display of the text
A string that is used to manipulate the text buffer
One is the callback stitching done.

Get yourself define properties in the constructor

This is the last Init method used to display the stitching of the text

The final effect is the effect of just beginning to advertise.
Welcome to the bricks and support Thank you

It's not a project, just a class. Do not upload the source code to paste this class here

 PackageCom.youthcommunity.ui.customview;ImportAndroid.content.Context;ImportAndroid.content.res.TypedArray;ImportAndroid.os.Handler;ImportAndroid.os.Message;ImportAndroid.util.AttributeSet;ImportAndroid.widget.TextView;ImportCOM.YOUTHCOMMUNITY.R;ImportJava.util.ArrayList;/** * Created by jsion on 16/1/8. * * Public  class appendtextview extends TextView {    Private Static Final intAppend_flag =Ten;Private Static Final intAppend_finishi = at;PrivateString textforshow;PrivateStringBuffer Textforappend;Private intTextLength;PrivateArraylist<string> Alltextchars;PrivateHandler Handler =NewHandler () {@Override         Public void Handlemessage(Message msg) {Super. Handlemessage (msg);Switch(msg.what) { CaseAppend_flag:settext (((StringBuffer) msg.obj). toString ()); Break; CaseAppend_finishi://Setup Complete                    if(Onhasfinishset! =NULL) {Onhasfinishset.hasfinishset (); } Break; }        }    }; Public  interface onhasfinishset {        voidHasfinishset (); }PrivateOnhasfinishset Onhasfinishset; Public void Setonhasfinishset(Onhasfinishset Onhasfinishset) { This. Onhasfinishset = Onhasfinishset; } Public Appendtextview(Context context) { This(Context,NULL); } Public Appendtextview(context context, AttributeSet attrs) { This(Context, Attrs,0); } Public Appendtextview(context context, AttributeSet attrs,intDEFSTYLEATTR) {Super(Context, attrs, defstyleattr); TypedArray a = Context.gettheme (). Obtainstyledattributes (Attrs, R.styleable.appendtextview, Defstyleattr,0);intn = a.getindexcount (); for(inti =0; I < n; i++) {intattr = A.getindex (i);Switch(attr) { CaseR.styleable.appendtextview_titletext:textforshow = a.getstring (attr); Break;        }} a.recycle ();    Init (); }/** * Gets its own defined attribute after initialization */    Private void Init() {textforappend =NewStringBuffer ();        TextLength = Textforshow.length (); Alltextchars =NewArraylist<string> (); for(inti =0; i < textLength; i++) {Alltextchars.add (Textforshow.charat (i) +""); }NewThread (NewRunnable () {@Override             Public void Run() { for(intj =0; J < Alltextchars.size ();                    J + +) {Message msg = Handler.obtainmessage ();                    Msg.what = Append_flag;                    Msg.obj = Textforappend.append (Alltextchars.get (j)); Handler.sendmessage (msg);Try{Thread.Sleep ( $); }Catch(Interruptedexception e)                    {E.printstacktrace ();                }} Message msg = Handler.obtainmessage ();                Msg.what = Append_finishi;            Handler.sendmessage (msg);    }}). Start (); }}

Exactly all over. I hope you continue to support Sohot>>>>>>>>>sohot.

The Apeendtextview of Android_youtharea

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.