Подтвердить что ты не робот

Android: пульсирующий фон программно

В настоящее время я создаю приложение для Android, где кто-то может ввести свое имя, нажать кнопку, а затем просто возвращает свое имя.

Одним из эффектов, который я хотел бы достичь с этим, является эффект, когда после нажатия кнопки вход и кнопка исчезают (до завершения этого бита до сих пор), а затем цвет фона в представлении MainActivity будет делать рябь (от центра) с новым цветом, в конечном счете изменяя полный цвет фона.

Как я буду делать это программно, так как я могу только найти учебники по добавлению рядов к кнопкам при нажатии?

4b9b3361

Ответ 1

EDIT:

Я проверил это, сделав небольшое приложение

Прежде всего, скройте представление, которое вы хотите показать в этой анимации.

Вид может быть из одного и того же макета, а в xml его видимость должна быть невидимой, чтобы анимация отображала.

Вы можете установить высоту и ширину представления для match parent, если вы хотите создать полноэкранную анимацию ...

Возьмите свое оригинальное и открытое представление как в рамочном макете

В моем случае я использовал это:

 <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <TextView android:text="Hello World!"                    
                android:layout_width="wrap_content"
                android:textSize="20sp"
                android:layout_height="wrap_content" />
            <LinearLayout 
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical" android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@color/colorPrimaryDark"
            android:id="@+id/revealiew"
            android:visibility="invisible"
            >
</FrameLayout>

то в вашей деятельности на button click или в каком-либо событии выполните следующее:

    fab.setOnClickListener(new View.OnClickListener() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void onClick(View view) {
                // previously invisible view
                View myView = findViewById(R.id.revealview);

// get the center for the clipping circle
                int cx = myView.getWidth() / 2;
                int cy = myView.getHeight() / 2;

// get the final radius for the clipping circle
                int finalRadius = Math.max(myView.getWidth(), myView.getHeight());

// create the animator for this view (the start radius is zero)
                Animator anim =
                        ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);

                //Interpolator for giving effect to animation
                anim.setInterpolator(new AccelerateDecelerateInterpolator());
                // Duration of the animation
                anim.setDuration(1000);

// make the view visible and start the animation
                myView.setVisibility(View.VISIBLE);
                anim.start();
            }
        });
    }

Прикрепленный GIF для вашей справки

Подробную информацию о официальной документации можно найти здесь: http://developer.android.com/training/material/animations.html

Ответ 2

То, что вы описываете, - это выявить эффект на фоне.

Из официального документа вы можете найти готовые примеры:

1) Вот как выявить ранее невидимый взгляд с использованием эффекта раскрытия:

// previously invisible view
View myView = findViewById(R.id.my_view);

// get the center for the clipping circle
int cx = myView.getWidth() / 2;
int cy = myView.getHeight() / 2;

// get the final radius for the clipping circle
int finalRadius = Math.max(myView.getWidth(), myView.getHeight());

// create the animator for this view (the start radius is zero)
Animator anim =
    ViewAnimationUtils.createCircularReveal(myView, cx, cy, 0, finalRadius);

// make the view visible and start the animation
myView.setVisibility(View.VISIBLE);
anim.start();

2) Вот как скрыть эффект видимости с помощью эффекта раскрытия:

// previously visible view
final View myView = findViewById(R.id.my_view);

// get the center for the clipping circle
int cx = myView.getWidth() / 2;
int cy = myView.getHeight() / 2;

// get the initial radius for the clipping circle
int initialRadius = myView.getWidth();

// create the animation (the final radius is zero)
Animator anim =
    ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);

// make the view invisible when the animation is done
anim.addListener(new AnimatorListenerAdapter() {
    @Override
    public void onAnimationEnd(Animator animation) {
        super.onAnimationEnd(animation);
        myView.setVisibility(View.INVISIBLE);
    }
});

// start the animation
anim.start();

В приложении вы можете использовать цветной фоновый слой (невидимый в начале), а затем использовать эффект раскрытия на нем.