How to realize the effect of Racing Lantern in android
This article is about how to achieve the effect of racing lanterns in android. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Implementation steps:
Step 1: create a layout page
Step 2: write java code in activity
Package com.example.smallbag.autoscrolltext; import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.text.Html;import android.text.TextUtils;import android.text.method.LinkMovementMethod;import android.widget.TextView; public class MainActivity extends AppCompatActivity {@ Override protected void onCreate (Bundle savedInstanceState) {super.onCreate (savedInstanceState); setContentView (R.layout.activity_main); TextView textView = (TextView) findViewById (R.id.textview) String html = "on the morning of January 25th, the political Bureau of the CPC Central Committee held its 12th collective study on the all-media era and the development of media integration at the people's Daily. Through People's Daily, I would like to extend New year's condolences and best wishes to journalists across the country. " / / CharSequence charSequence = Html.fromHtml (html); / / enable text to have html features, such as hyperlink textView.setText (html); textView.setMovementMethod (LinkMovementMethod.getInstance ()); / / add manual sliding function textView.setEllipsize (TextUtils.TruncateAt.valueOf ("MARQUEE")); / / add racing lantern function textView.setMarqueeRepeatLimit (Integer.MAX_VALUE); / / number of racing lantern scrolls, where the maximum textView.setSingleLine (true) has been set / / set to display textView.setFocusable (true) on a single line; / / get focus textView.setFocusableInTouchMode (true); / / ability to gain focus by touching}}
Setting the properties of textview can also be set directly in the layout file. The blogger cannot scroll when setting it in the layout file. The reason is unknown. Just pay attention.
Thank you for reading! This is the end of this article on "how to achieve the effect of racing lanterns in android". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!