我正在使用 android 的 API19 转换为 TextView 制作动画。我定义了一个我希望过渡到的场景:
scene = Scene.getSceneForLayout(rootLayout, R.layout.my_scene, this);
我定义了我的转换:
myTransition = new ChangeBounds();
myTransition.setDuration(1000);
myTransition.setInterpolator(new BounceInterpolator());
我开始过渡:
TransitionManager.go(场景,myTransition);
只要我对 android:text
进行硬编码,一切都会正常。 my_scene.xml
如下所示:
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:id="@+id/textview1"
android:layout_width="100dp"
android:layout_height="100dp"
android:text="text1"/>
</merge>
具有相同 id 的相同 TextView 位于 activity_main.xml
中,但位置不同。
当我尝试使用 setText() 动态设置文本时,它不会更改文本。我对这个转换 API 不是很有经验,所以非常感谢您的帮助。
最佳答案
定义场景进入 Action ,然后调用TransitionManager中的go()方法。这是代码 fragment
scene = Scene.getSceneForLayout(rootLayout, R.layout.my_scene, this); scene.setEnterAction(new Runnable() {
@Override
public void run() {
TextView textView1 = (TextView)rootLayout.findViewById(R.id.textView1);
textView1.setText("Hello World");
}
}); TransitionManager.go(scene, myTransition);
关于Android 转换 (API 19) - 如何在转换之前在 TextView 上 setText()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29657892/