我将代码留在下面,以了解发生了什么,错误是什么,我正在尝试在那里制作动画,我正在遵循Java教程,但我在kotlin进行 那里他们对课程有影响,而错误在animationUtilitis部分中,我不知道这是否是在kotlin中正确的方法:
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.ImageView
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import androidx.viewpager.widget.ViewPager
import com.airbnb.lottie.LottieAnimationView
import com.yr.iolite.R
import kotlinx.android.synthetic.main.activity_splash.*
class SplashActivity : AppCompatActivity()
{
var bg: ImageView? = null
var logo: ImageView? = null
var penguin: LottieAnimationView? = null
var anim: Animation? = null
//private val viewPager : ViewPager? = null
private var pagerAdapter : ScreenSliderPagerAdapter? = null
override fun onCreate(savedInstanceState: Bundle?)
{
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_splash)
inicializar()
}
private fun inicializar()
{
bg = findViewById(R.id.bg_snow_splash)
logo = findViewById(R.id.logo_splash)
penguin = findViewById(R.id.penguin_splash)
val viewPager : ViewPager = findViewById(R.id.swipe_screen)
pagerAdapter = ScreenSliderPagerAdapter(supportFragmentManager)
viewPager.adapter = pagerAdapter
anim = AnimationUtils.LoadAnimation(this, R.anim.swipe_screen_anim)
viewPager.startAnimation(anim)
bg_snow_splash.animate().apply {
duration = 1000
startDelay = 4000
translationY(-1600f)
}
logo_splash.animate().apply {
duration = 1000
startDelay = 4000
translationY(-1400f)
}
penguin_splash.animate().apply {
duration = 1000
startDelay = 4000
translationY(1400f)
}
}
private class ScreenSliderPagerAdapter (fm : FragmentManager) : FragmentStatePagerAdapter(fm)
{
val NUM_TABS = 3
override fun getItem(position: Int): Fragment
{
return when (position)
{
0 -> SwipeFragement1()
1 -> SwipeFragement2()
else -> SwipeFragement3()
}
}
override fun getCount(): Int = NUM_TABS
}
}
在这里,我还保留了屏幕截图中出现的错误:
答案 0 :(得分:1)
替换您的
anim = AnimationUtils.LoadAnimation(this, R.anim.swipe_screen_anim)
对此
anim = AnimationUtils.loadAnimation(this, R.anim.swipe_screen_anim)