Get the App
SLTechnology News&Howtos  ›  Development  › 

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

Shulou Source: shulou.com Published: 2022-06-02 02:42:55 10月03日 Update

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!

Tags: Text dynamic up and down code multiline content animation attributes layout learning practical deeper no interest practicality practical object simple operation file method Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft Docker macOS Huawei MySQL