2017-12-07 3 views
1

Ich versuche, die kreisförmige Enthüllungsanimation für einen Knopfklick anzuwenden, der von der SplashScreen-Aktivität zur MainActivity übergeht. Ich habe fast alle Lösungen von Menschen ausprobiert, aber ich bin nicht in der Lage zu verstehen, das Konzept der Erstellung der benutzerdefinierten Animationen wie die kreisförmige Enthüllung für die Änderung der Aktivität. Ich kann es erfolgreich auf die aktuellen Aktivitätenansichten anwenden, aber nicht auf die Aktivitätsübergänge.Wie man kreisförmige Enthüllung für Aktivitätsänderung anwendet?

Hier ist meine 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); 
    } 


    } 

ich die benutzerdefinierte Animation (CircularReveal), wenn die Schaltfläche geklickt wird machen wollen und die Splashscreen-Übergänge zu MainActivity. Es wird großartig sein, wenn Sie den Code erklären können. Ich versuche nun seit über einem Tag eine Lösung dafür zu finden und kann immer noch nichts erreichen. Und auch darauf hin, die notwendigen Veränderungen hier in XML

getan werden ist 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> 

Hier ist mein 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> 

Antwort

Verwandte Themen