2014-01-31 10 views
6

Ich benutze diesen Code zu TextzugWie kann Text in Android von links nach rechts verschoben werden?

der Text bewegt sich korrekt von rechts zu machen

nach links will ich den Text in Textview Schritt machen von links nach rechts

  <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

U die schütteln mögen hinzufügen Text oder möchte einfach verschieben ?? –

Antwort

4

Verwendung unter xml code in anim ordner unter res:

<?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> 

Und fügen Sie das einfach zu Ihnen r Textview:

yourTextView.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.move)); 
+0

Dies ist Bewegung nach rechts, aber wenig Platz –

+0

Sie können Bewegungsposition unter XML-Attribute 'fromXDelta' und' toXDelta' –

1

Wenn Sie den Text als in Ihrer Tätigkeit Verwenden

Animation shake = AnimationUtils.loadAnimation(YourActivity.this, R.anim.shake); 
      YOUR_TEXT_VIEW.startAnimation(shake); 

erstellen Ordnernamen anim in res dh res ..> Anim schütteln wollen und schaffen zwei xml in anim Ordner 1) shake.xml 2) cycle.xml

in Ihrem shake.xml schreiben

<?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" /> 

und in Ihrem cycle.xml schreiben

<?xml version="1.0" encoding="utf-8"?> 
<cycleInterpolator xmlns:android="schemas.android.com/apk/res/android" android:cycles="10" /> 

in android Textansicht Animation Text Enjoy :)

+0

dies ist Shake für Text, aber ich muss nur Text bewegen von links nach rechts anstelle von rechts nach links –

+0

Ja Ich schrieb, wenn du den Text friom links schütteln möchtest, als das oben genannte 1 ist Antwort :) –

0

nach rechts Animation Links:

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  

Wiederholte Animation (für zB. von links nach rechts und von rechts nach links):

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(4); // animation repeat count 
    animation.setRepeatMode(2); // repeat animation (left to right, right to left) 

    animation.setFillAfter(true); 
    your_view .startAnimation(animation);//your_view for mine is imageView 
+0

dieses bewegt sich auf und ab – basha

0

Ich weiß, ich bin ein zu spät, aber die einfachste Art und Weise zu beantworten, ist zu Ihrem Textview in der XML-Datei

android:layoutDirection="rtl" 
Verwandte Themen