欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Android使用kotlin實(shí)現(xiàn)多行文本上下滾動播放

 更新時間:2022年01月13日 08:22:55   作者:鳳洋  
這篇文章主要為大家詳細(xì)介紹了Android使用kotlin實(shí)現(xiàn)多行文本的上下滾動播放,文中示例代碼介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們可以參考一下

最近在項(xiàng)目中用到了上下滾動展示條目內(nèi)容,就使用kotlin簡單編寫實(shí)現(xiàn)了一下該功能。

使用kotlin實(shí)現(xiàn)viewflipper展示textview的上下滾動播放

其中包含了kotlin的一些簡單的使用

- 首先是在布局文件中如下代碼:

<ViewFlipper
? ? ? ? android:id="@+id/viewFlipper"
? ? ? ? android:layout_width="match_parent"
? ? ? ? android:layout_height="200dp"
? ? ? ? android:background="#555"
? ? ? ? android:flipInterval="2000">
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/one"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:text="這是靜態(tài)添加的條目1"
? ? ? ? ? ? android:textSize="25sp"
? ? ? ? ? ? android:layout_gravity="center"
? ? ? ? ? ? android:textColor="#f99" />
? ? ? ? <TextView
? ? ? ? ? ? android:id="@+id/two"
? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? android:text="這是靜態(tài)添加的條目2"
? ? ? ? ? ? android:textSize="25sp"
? ? ? ? ? ? android:layout_gravity="center"
? ? ? ? ? ? android:textColor="#f99" />
</ViewFlipper>

布局中首先已經(jīng)動態(tài)添加了兩條textview文本,也可以如下面代碼中進(jìn)行動態(tài)添加textview文本

在kotlin代碼中如下:

import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Gravity
import android.view.animation.AnimationUtils
import android.widget.TextView
import kotlinx.android.synthetic.main.activity_flip.*

class FlipActivity : AppCompatActivity() {

? ? override fun onCreate(savedInstanceState: Bundle?) {
? ? ? ? super.onCreate(savedInstanceState)
? ? ? ? setContentView(R.layout.activity_flip)

? ? ? ? //給viewFlipper設(shè)置進(jìn)出場的動畫格式
? ? ? ?viewFlipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.bottom_in))

viewFlipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.top_out))

? ? ? ? //使用kotlin動態(tài)的創(chuàng)建textview的對象
? ? ? ? var textview: TextView = TextView(this)
? ? ? ? //kotlin中使用的是直接如下 ?.屬性 來設(shè)置的,不再用setxxx設(shè)置屬性
? ? ? ? textview.text = "這是一個動態(tài)添加的標(biāo)題xxxx"
? ? ? ? textview.textSize = 25f
? ? ? ? textview.setTextColor(R.color.blue)
? ? ? ? textview.gravity = Gravity.CENTER

? ? ? ? viewFlipper.addView(textview) //動態(tài)添加一條textview(靜態(tài)動態(tài)添加都可以)
? ? ? ? viewFlipper.startFlipping() ?//啟動viewflipper

? ? }
}

在kotlin中可以直接使用 import kotlinx.android.synthetic.main.activity_flip.* 語句導(dǎo)入,之后就可以入代碼中直接書寫viewFlipper 不用在進(jìn)行findviewbyid進(jìn)行初始化了;
其中給viewFlipper設(shè)置進(jìn)出場動畫如下:

bottom_in.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
? ? <translate
? ? ? ? android:duration="1000"
? ? ? ? android:fromYDelta="100%p"
? ? ? ? android:toYDelta="0"/>
</set>

top_out.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
? ? <translate
? ? ? ? android:duration="1000"
? ? ? ? android:fromYDelta="0"
? ? ? ? android:toYDelta="-100%p" />
</set>

以上就是多行文本的上下滾動的實(shí)現(xiàn),如果想實(shí)現(xiàn)其他的動畫切換可以更改 動畫xml進(jìn)行實(shí)現(xiàn)

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論