1

我正在尝试将圆形显示动画应用于从 SplashScreen 活动转换到 MainActivity 的按钮单击。我已经尝试了人们给出的几乎所有解决方案,但我无法理解创建自定义动画的概念,例如用于活动更改的圆形显示。我可以成功地将其应用于当前活动视图,但不能应用于活动转换。

这是我的 SplashScreen.java

public class SplashScreen extends AppCompatActivity {
    boolean isOpen = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {


        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash_screen);
        final ImageButton startButton = (ImageButton) findViewById(R.id.button);
        final TextView textView = (TextView)findViewById(R.id.tv1);
        fadeInTextView(textView);
        circularRevealDelayedImageButton(startButton);

    }


    public void fadeInTextView(final TextView textView){
        textView.postDelayed(new Runnable() {
            @Override
            public void run() {
                final TextSwitcher textSwitcher = (TextSwitcher)findViewById(R.id.ssj1);
                textSwitcher.setFactory(new ViewSwitcher.ViewFactory() {

                    public View makeView() {
                        // TODO Auto-generated method stub
                        // create a TextView
                        TextView t = new TextView(SplashScreen.this);
                        // set the gravity of text to top and center horizontal
                        // set displayed text size
                        Resources r = getResources();
                        float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 23, r.getDisplayMetrics());
                        t.setTextSize(px);
                        t.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
                        t.setPadding(0,240,0,0);
                        Typeface type = Typeface.createFromAsset(getAssets(),"fonts/allura.ttf");
                        t.setTypeface(type);
                        t.setTextColor(getResources().getColor(R.color.black));
                        return t;
                    }
                });
                Animation anim = AnimationUtils.loadAnimation(getApplicationContext(),android.R.anim.fade_in);
                textView.setVisibility(View.VISIBLE);
                textView.setAnimation(anim);
                textSwitcher.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        textSwitcher.setText("Hey There\nJaadi :)");
                    }
                },2000);

                textSwitcher.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        textSwitcher.setText("");
                    }
                },7000);
                textSwitcher.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        textSwitcher.setText("Press That\nHeart\nFor Me");
                    }
                },9000);


            }
        },3000);


    }


    public void circularRevealDelayedImageButton(final ImageButton startButton){
        startButton.postDelayed(new Runnable() {
            @Override
            public void run() {
                // get the center for the clipping circle
                int cx = startButton.getWidth() / 2;
                int cy = startButton.getHeight() / 2;

// get the final radius for the clipping circle
                float finalRadius = (float) Math.hypot(cx, cy);

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

// make the view visible and start the animation
                startButton.setVisibility(View.VISIBLE);
                anim.setDuration(350);
                anim.start();
                startButton.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        startActivity(new Intent(SplashScreen.this, MainActivity.class));
                      // WHAT TO ADD HERE??? FOR CIRCULAR REVEAL ANIMATION FOR THE ABOVE INTENT???
                    }
                });
            }
        },13000);
    }


    }

当单击按钮并且 SplashScreen 转换为 MainActivity 时,我想制作自定义动画 (CircularReveal)。如果您能解释代码,那就太好了。我正在尝试解决这个问题超过一天,但仍然无法掌握任何东西。并建议需要在XML

这是 MainActivity.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:id="@+id/layoutcontent"
    android:visibility="invisible"
    android:transitionName="transition"
    android:layout_height="match_parent"
    tools:context="com.yourstrulyssj.foru.MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</RelativeLayout>

这是我的 SplashScreen.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/layoutmain"
    android:transitionName="transition"
    tools:context="com.yourstrulyssj.foru.SplashScreen">
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/rwall"
        android:scaleType="centerCrop"

        />

    <TextSwitcher
        android:id="@+id/ssj1"
        android:layout_width="300dip"
        android:layout_height="400dip"

        android:layout_alignStart="@+id/tv1"
        android:layout_alignTop="@+id/tv1"
        android:inAnimation="@android:anim/fade_in"
        android:outAnimation="@android:anim/fade_out">

    </TextSwitcher>

    <TextView
        android:id="@+id/tv1"
        android:layout_width="300dip"
        android:layout_height="400dip"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="51dp"
        android:background="@drawable/back1"
        android:fontFamily="cursive"
        android:gravity="center"
        android:text=""
        android:textSize="80dip"
        android:visibility="invisible" />

    <ImageButton
        android:id="@+id/button"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="26dp"
        android:layout_weight="1"
        android:background="@drawable/roundedbutton"
        android:src="@drawable/ic_favorite_black_24dp"
        android:visibility="invisible" />
</RelativeLayout>
4

1 回答 1

0

您可以使用此链接:此处presentActivity让您了解如何在从一个班级转移到另一个班级时发挥作用。

https://android.jlelse.eu/a-little-thing-that-matter-how-to-reveal-an-activity-with-circular-revelation-d94f9bfcae28

希望对您有所帮助。

于 2017-12-07T12:18:41.620 回答