Страницы

Поиск по вопросам

понедельник, 8 октября 2018 г.

Анимация снизу вверх циклическая

Как сделать анимацию, в которой задний фон будет уходить вверх и появляться снизу? Не так как в ответе, а чтобы картинка двигалась вверх и попиксельно вылезала снизу сразу. Тоесть вот ряд пикселей ушел наверх и сразу появился снизу


Ответ

Если вы хотите анимировать просто картинку, тогда всё просто. Внизу неё добавим ImageView, которому мы установим основную картинку. Разметка:



Activity:
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main);
final ImageView content = findViewById(R.id.content); final ImageView img = (ImageView) findViewById(R.id.imageView);
img.setImageDrawable(content.getDrawable());
final int s = Animation.RELATIVE_TO_SELF; final TranslateAnimation animForContent = new TranslateAnimation(s, 0f, s, 0f, s, 0f, s, 1f); animForContent.setDuration(3000); final TranslateAnimation animForImg = new TranslateAnimation(0f, s, 0f, s, -1f, s, 0f); animForImg.setDuration(3000); animForImg.setAnimationListener(new AnimationListener() { public void onAnimationStart(Animation animation) {} public void onAnimationRepeat(Animation animation) {}
@Override public void onAnimationEnd(Animation animation) { img.startAnimation(animForImg); content.startAnimation(animForContent); } }); img.startAnimation(animForImg); content.startAnimation(animForContent); }

Комментариев нет:

Отправить комментарий