我使用此代码移动文本,并从右向左正确移动。
尽管如此,我想让 TextView 中的文字从左向右移动。
这是我目前的代码:
<TextView
android:id="@+id/mylinenews"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
android:ellipsize="marquee"
android:focusable="true"
android:focusableInTouchMode="true"
android:marqueeRepeatLimit="marquee_forever"
android:scrollHorizontally="true"
android:singleLine="true"
android:text="textmoving textmoving textmoving textmoving textmoving textmoving textmoving textmoving textmoving textmoving "
android:textColor="#fff"
/>
如何修改此代码以使文本从左向右移动?
答案 0 :(得分:4)
在res:
下的anim文件夹中使用以下xml代码<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">
<translate
android:fromXDelta="-3%p"
android:toXDelta="3%p"
android:duration="1200" />
</set>
并且,只需将其添加到您的textview:
yourTextView.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.move));
答案 1 :(得分:2)
如果您想要动摇文字而不是在您的活动中使用
Animation shake = AnimationUtils.loadAnimation(YourActivity.this, R.anim.shake);
YOUR_TEXT_VIEW.startAnimation(shake);
在res中创建文件夹名称动画,即res ..&gt;动画并在动画文件夹中创建两个xml
1)shake.xml
2)cycle.xml
在你的shake.xml中写
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0" android:toXDelta="20" android:duration="7000"
android:interpolator="@anim/cycle" />
并在你的cycle.xml中写
<?xml version="1.0" encoding="utf-8"?>
<cycleInterpolator xmlns:android="schemas.android.com/apk/res/android" android:cycles="10" />
在Android文本视图中享受动画文字:)
答案 2 :(得分:0)
从左到右动画:
new Vue({
el: '#main',
data: {
position: 0,
modules: [
{context: {name: 'article-init-a', prepared: false}, type: 'type-a'},
{context: {name: 'article-init-b', prepared: false}, type: 'type-b'},
{context: {name: 'article-init-c', prepared: false}, type: 'type-c'}
]
},
methods: {
insertA: function () {
this.modules.splice(this.position, 0, {context: {name: 'new-article-a', prepared: false}, type: 'type-a', prepared: false})
},
....
....
重复动画(例如从左到右,从右到左):
TranslateAnimation animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 1500.0f); // new TranslateAnimation (float fromXDelta,float toXDelta, float fromYDelta, float toYDelta)
animation.setDuration(1500); // animation duration
animation.setRepeatCount(1); // animation repeat count
animation.setFillAfter(false);
your_view .startAnimation(animation);//your_view for mine is imageView
答案 3 :(得分:0)
我知道我回答太晚了,但最简单的方法是在xml文件中添加你的textview
android:layoutDirection="rtl"
答案 4 :(得分:0)
animation.setDuration(1500); // animation duration
animation.setRepeatCount(4); // animation repeat count
animation.setRepeatMode(2); // repeat animation (left to right, right to left)
animation.setFillAfter(true);
textview.startAnimation(animation);
答案 5 :(得分:0)
从左至右移动文本视图的工作代码为
TextView tv2 = (TextView) findViewById(R.id.textscroll);
TranslateAnimation animation = new TranslateAnimation(0.0f, 1500.0f, 0.0f, 0.0f); // new TranslateAnimation (float fromXDelta,float toXDelta, float fromYDelta, float toYDelta)
animation.setDuration(7500); // animation duration, change accordingly
animation.setRepeatCount(1); // animation repeat count
animation.setFillAfter(false);
tv2 .startAnimation(animation);//your_view for which you need animation