Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use kotlin to realize multi-line text scrolling up and down in Android

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "how to use kotlin to achieve multi-line text scrolling up and down in Android", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to use kotlin to achieve multi-line text scrolling up and down in Android".

Using kotlin to realize the up and down scrolling playback of viewflipper display textview

It contains some simple uses of kotlin

-the first is the following code in the layout file:

Two pieces of textview text have been dynamically added to the layout, or you can add textview text dynamically as shown in the following code

In the kotlin code is as follows:

Import android.os.Bundleimport android.support.v7.app.AppCompatActivityimport android.view.Gravityimport android.view.animation.AnimationUtilsimport android.widget.TextViewimport kotlinx.android.synthetic.main.activity_flip.*class FlipActivity: AppCompatActivity () {override fun onCreate (savedInstanceState: Bundle?) {super.onCreate (savedInstanceState) setContentView (R.layout.activity_flip) / / set the viewFlipper entry and exit animation format viewFlipper.setInAnimation (AnimationUtils.loadAnimation (this) R.anim.bottom_in)) viewFlipper.setOutAnimation (AnimationUtils.loadAnimation (this,R.anim.top_out)) / / use kotlin to dynamically create textview objects var textview: TextView = TextView (this) / / kotlin is used directly as follows. Property, instead of using setxxx to set the property textview.text = "this is a dynamically added title xxxx" textview.textSize = 25f textview.setTextColor (R.color.blue) textview.gravity = Gravity.CENTER viewFlipper.addView (textview) / / dynamically add a textview (static and dynamic add) viewFlipper.startFlipping () / / start viewflipper}}

In kotlin, you can directly use the import kotlinx.android.synthetic.main.activity_flip.* statement to import, and then you can write viewFlipper directly into the code without initializing the findviewbyid.

Animate the entry and exit of viewFlipper as follows:

Bottom_in.xml

Top_out.xml

At this point, I believe you have a deeper understanding of "how to use kotlin to achieve multi-line text scrolling up and down in Android". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report