lottie 换图,换文字的方法

binding.originalTextView.setImageAssetDelegate(object : ImageAssetDelegate {
    override fun fetchBitmap(asset: LottieImageAsset): Bitmap {

        return Bitmap.createBitmap(asset.bitmap!!)
    }

})

val textDelegate = TextDelegate(binding.dynamicTextView)
val textDelegate2 = TextDelegate(binding.originalTextView)
binding.nameEditText.addTextChangedListener(object : TextWatcher {
    override fun afterTextChanged(s: Editable?) {
        textDelegate.setText("88bg", s.toString()).also {  }
        textDelegate2.setText("Lv.999", s.toString()).also {  }
    }

    override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {}

    override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {}
})
binding.dynamicTextView.setTextDelegate(textDelegate)
binding.originalTextView.setTextDelegate(textDelegate2)
Android布局中,你可以通过结合Lottie动画View和LinearLayout或者其他容器布局(如FrameLayout或RelativeLayout)来实现这样的效果。下面是一个基本步骤的示例: 1. 首先,你需要安装Lottie Android库。如果你还没有,可以在build.gradle文件的dependencies部分添加以下依赖: ```gradle implementation 'com.airbnb.lottie:lottie-android:4.0.0' ``` 2. 然后,在XML布局文件中创建两个视图,一个用于放置Lottie动画,另一个用于文本。例如,使用LinearLayout: ```xml <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <com.airbnb.lottie.LottieAnimationView android:id="@+id/lottie_view" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" app:lottie_fileName="your_animation.json" /> <!-- 这里是右侧的文字视图 --> <TextView android:id="@+id/text_view" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="3" android:text="这是你的文本内容" /> </LinearLayout> ``` 这里,`android:layout_weight`属性用于分配左右两个视图的空间比例。Lottie动画占总宽度的1/4,而剩余的3/4留给TextView。 3. 接下来,在对应的Activity或Fragment中初始化这两个视图,并设置动画: ```java LottieAnimationView lottieView = findViewById(R.id.lottie_view); lottieView.setAnimation(LottieFactory.load("path_to_your_animation.json")); TextView textView = findViewById(R.id.text_view); textView.setText("这是你的文本内容"); ``` 替换`"path_to_your_animation.json"`为你的Lottie动画文件的实际路径。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值