0

Здравствуйте! Имеем хмл анимации текста вида

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fillAfter="true"

android:shareInterpolator="false"
android:ordering="sequentially"

android:repeatMode="restart"
android:repeatCount="infinite"
>

<alpha
    android:fromAlpha="0.0"
    android:toAlpha="1.0"
    />

<alpha

    android:fromAlpha="1.0"
    android:toAlpha="0.0"

    />

Требуется несколько строк заанимировать в бесконечность так, чтобы они не накладывались появлением друг на друга. Туплю безумно, подскажите, пожалуйста! Код

private Animation textAnim;
private Animation textAnim2;

textAnim = AnimationUtils.loadAnimation(getApplicationContext(),      R.anim.for_text);
textAnim.setAnimationListener(animationListener);
textAnim.setDuration(3000);
textAnim.setStartOffset(1000);
final long currAnimTime = AnimationUtils.currentAnimationTimeMillis();
textAnim.setStartTime(currAnimTime+500);
text.startAnimation(textAnim);

textAnim2 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.animm);
textAnim2.setStartOffset(1000);
textAnim2.setAnimationListener(animationListener2);
textAnim2.setStartTime(currAnimTime + textAnim.getDuration());
textAnim2.setDuration(3000);
text2.startAnimation(textAnim2);

text.setAnimation(textAnim);
text2.setAnimation(textAnim2);

хмл текста

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="fill_horizontal|fill_vertical"

tools:context=".MainActivity" >

<ImageView
    android:id="@+id/bg"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:contentDescription="@string/bg"

     />


<TextView
    android:id="@+id/textView"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal|center_vertical"
    android:text="Hey! I did it!"
    android:textSize="42sp"
    />

<TextView
    android:id="@+id/textView2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal|center_vertical"
    android:text="Ok. Let's work!"
    android:textSize="42sp"
    />

2
  • было бы не плохо если бы выложили и разметку layout-a, где эти textview находятся.
    – s_klepcha
    8 сен 2015 в 11:40
  • Вам нужно создать массив строк, которые будете последовательно выводить. Затем в ОДИН И ТОТ ЖЕ TextView сетить их с определенным интервалом (чтобы анимация исчезновения успела отработать). Если при этом требуется выполнять другие задачи, то изменение текста в нашем TextView нужно вывести в отдельный поток.
    – pavlofff
    8 сен 2015 в 12:28

2 ответа 2

0

замените разметку на эту

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >

<ImageView
    android:id="@+id/bg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:contentDescription="@string/bg"/>

<TextView
    android:id="@+id/textView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="fill"
    android:layout_weight="1"
    android:gravity="center_horizontal|center_vertical"
    android:text="Hey! I did it!"
    android:textSize="42sp" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="fill"
    android:layout_weight="1"
    android:gravity="center_horizontal|center_vertical"
    android:text="Ok. Let&apos;s work!"
    android:textSize="42sp" />

   </LinearLayout>
8
  • Этот код сместит чуть ниже одну строку? Мне нужно, чтоб строчка появлялась только одна. потом она тихонечко исчезает, и через секунду начинает плавно появляться вторая строчка, и тд. Нужно, чтоб анимация появления не накладывалась друг на дружку, а между появлениями была пауза. 8 сен 2015 в 12:02
  • в таком случае стоит попробовать AnimationListener
    – s_klepcha
    8 сен 2015 в 12:08
  • Я пытаюсь сделать там проверку, если одна анимация true, то вторая не начнется. Пока хрень какая то, андроид студио вообще не компилит, и ничего не пишет(( 8 сен 2015 в 12:09
  • а может когда одна анимация отработала, в методе onAnimationEnd запускать другую анимацию, а вьюху первой прятать и наоборот?
    – s_klepcha
    8 сен 2015 в 12:13
  • Таким образом только раз обе анимации отрабатывают. Надо что то дописать в AnimationRepeat наверное 8 сен 2015 в 12:28
0

Ковырялась вчера, сегодня получилось. Листнер не нужен. Указать задержку для обеих строк одинаковую, для второй строки указать старт тайм, равный задержке и длине первой анимации.

    init();

    long startOffSet = 3000;//длина каждой анимации, они одинаковые
    a1.setStartOffset(startOffSet);
    long currAnimTime = AnimationUtils.currentAnimationTimeMillis();
    a2.setStartOffset(startOffSet);
    a2.setStartTime(currAnimTime + startOffSet);

    t1.setAnimation(a1);
    t2.setAnimation(a2);

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.