Skip to content

Instantly share code, notes, and snippets.

@ozodrukh
Created January 6, 2015 18:23
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozodrukh/c9343e7073907c5c5d2c to your computer and use it in GitHub Desktop.
Save ozodrukh/c9343e7073907c5c5d2c to your computer and use it in GitHub Desktop.
Fragment Circular Reveal animation
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.animation.AccelerateInterpolator;
import java.util.Random;
import butterknife.ButterKnife;
import butterknife.InjectView;
import codetail.animation.Animator;
import codetail.animation.ViewAnimationUtils;
import codetail.utils.ViewUtils;
public class RandomFragment extends Fragment {
@InjectView(R.id.container)
View container;
@InjectView(R.id.first)
View first;
@InjectView(R.id.second)
View second;
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
ViewUtils.setBackground(container, null);
return inflater.inflate(R.layout.sample_fragment, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
ButterKnife.inject(this, view);
ViewUtils.setBackground(view, null);
first.setBackgroundColor(randomColor());
second.setBackgroundColor(randomColor());
first.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
reveal();
ViewUtils.removeGlobalListeners(first, this);
}
});
}
void reveal(){
View view = container;
int finalRadius = Math.max(view.getWidth(), view.getHeight());
Animator animator =
ViewAnimationUtils.createCircularReveal(view, 0, 0, 0, finalRadius);
animator.setInterpolator(new AccelerateInterpolator());
animator.setDuration(3500);
animator.start();
}
static int randomColor(){
Random random = new Random();
return Color.HSVToColor(new float[]{
random.nextInt(360),
0.70f,
0.70f
});
}
}
<?xml version="1.0" encoding="utf-8"?>
<codetail.widget.RevealFrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container"
android:background="@null"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="2">
<FrameLayout
android:id="@+id/first"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
<FrameLayout
android:id="@+id/second"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
</codetail.widget.RevealFrameLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment