새 활동에 대한 순환 표시 전환
당 https://developer.android.com/training/material/animations.html
이
ViewAnimationUtils.createCircularReveal()
방법을 사용하면 클리핑 원을 애니메이션하여 뷰를 표시하거나 숨길 수 있습니다.이 효과를 사용하여 이전에 볼 수 없었던보기를 표시하려면 :
// previously invisible view View myView = findViewById(R.id.my_view); // get the center for the clipping circle int cx = (myView.getLeft() + myView.getRight()) / 2; int cy = (myView.getTop() + myView.getBottom()) / 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();
이것은보기를 드러내 기위한 것입니다. 이것을 사용하여 공유 요소없이 전체 활동을 순환 적으로 표시하려면 어떻게해야합니까?
특히, 내 searchActivity가 툴바의 검색 작업 버튼에서 원형으로 표시되기를 원합니다.
결과없이 반나절 동안의 솔루션을 찾고 나서 자체 구현을 생각해 냈습니다. 루트 레이아웃이 일치하는 투명한 활동을 사용하고 있습니다. 루트 레이아웃은로 표시 할 수있는보기입니다 createCircularReveal()
.
내 코드는 다음과 같습니다.
styles.xml의 테마 정의
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowBackground">@android:color/transparent</item>
</style>
AndroidManifest.xml의 활동 정의
<activity
android:name=".ui.CircularRevealActivity"
android:theme="@style/Theme.Transparent"
android:launchMode="singleTask"
/>
그런 다음 내 활동에 대한 레이아웃을 선언했습니다 (DrawerLayout를 선택하여 NavDrawer를 사용할 수 있습니다. 모든 레이아웃이 여기서 작동해야합니다.)
<android.support.v4.widget.DrawerLayout
android:id="@+id/drawer_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<FrameLayout
android:id="@+id/root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/honey_melon"
>
<!-- Insert your actual layout here -->
</FrameLayout>
</android.support.v4.widget.DrawerLayout>
중요한 것은 ID가있는 FrameLayout입니다 root_layout
. 이보기는 활동에 표시됩니다.
마지막으로 구현 CircularRevealActivity
하고 덮어 썼습니다 onCreate()
.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
overridePendingTransition(R.anim.do_not_move, R.anim.do_not_move);
setContentView(R.layout.activity_reveal_circular);
if (savedInstanceState == null) {
rootLayout.setVisibility(View.INVISIBLE);
ViewTreeObserver viewTreeObserver = rootLayout.getViewTreeObserver();
if (viewTreeObserver.isAlive()) {
viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
circularRevealActivity();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
rootLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
rootLayout.getViewTreeObserver().removeOnGlobalLayoutListener(this);
}
}
});
}
}
}
넣어 중요 circularRevealActivity()
로 OnGlobalLayoutListener
보기는 애니메이션 그려해야하기 때문.
circularRevealActivity()
Ishaan의 제안처럼 보입니다.
private void circularRevealActivity() {
int cx = rootLayout.getWidth() / 2;
int cy = rootLayout.getHeight() / 2;
float finalRadius = Math.max(rootLayout.getWidth(), rootLayout.getHeight());
// create the animator for this view (the start radius is zero)
Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, cx, cy, 0, finalRadius);
circularReveal.setDuration(1000);
// make the view visible and start the animation
rootLayout.setVisibility(View.VISIBLE);
circularReveal.start();
}
편집 1
에 대한 정의 R.anim.do_not_move
가 추가되었습니다. 그러나 디자인이 활동에 대한 기본 전환을 지정하지 않으면 해당 줄 없이도 작동해야합니다. 알려주세요
R.anim.do_not_move :
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:fromYDelta="0"
android:toYDelta="0"
android:duration="@android:integer/config_mediumAnimTime"
/>
</set>
CircularReveal
애니메이션 을 되돌리려면 startRadius
및 endRadius
인수를 바꿉니다. 또한 설정해야 AnimatorListener
하며 onAnimationEnd()
콜백 메서드에서을 호출 할 수 있습니다 finishAfterTransition()
. 를 누르 up navigation
거나를 클릭 할 때 사용됩니다 back button
.
활동을 떠날 때 순환 표시를 되돌리려면 onBackPressed ()에 다음 수정을 사용하십시오.
@Override
public void onBackPressed() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
int cx = rootLayout.getWidth();
int cy = 0;
float finalRadius = Math.max(rootLayout.getWidth(), rootLayout.getHeight());
Animator circularReveal = ViewAnimationUtils.createCircularReveal(rootLayout, cx, cy, finalRadius, 0);
circularReveal.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
rootLayout.setVisibility(View.INVISIBLE);
finish();
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
circularReveal.setDuration(400);
circularReveal.start();
}else{
super.onBackPressed();
}
}
나는 당신이 사용할 수 있다고 생각합니다 ActivityOptionsCompat.makeClipRevealAnimation
.
[ https://developer.android.com/reference/android/support/v4/app/ActivityOptionsCompat.html#makeClipRevealAnimation(android.view.View , int, int, int, int)] ( https://developer.android .com / reference / android / support / v4 / app / ActivityOptionsCompat.html # makeClipRevealAnimation (android.view.View , int, int, int, int))
ou have to draw the circle view, and after that you should create an animation to it.
Creating the circle view:
public class Circle extends View {
private static final int START_ANGLE_POINT = 90;
private final Paint paint;
private final RectF rect;
private float angle;
public Circle(Context context, AttributeSet attrs) {
super(context, attrs);
final int strokeWidth = 40;
paint = new Paint();
paint.setAntiAlias(true);
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(strokeWidth);
//Circle color
paint.setColor(Color.RED);
//size 200x200 example
rect = new RectF(strokeWidth, strokeWidth, 200 + strokeWidth, 200 + strokeWidth);
//Initial Angle (optional, it can be zero)
angle = 120;
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawArc(rect, START_ANGLE_POINT, angle, false, paint);
}
public float getAngle() {
return angle;
}
public void setAngle(float angle) {
this.angle = angle;
}
}
Creating the animation class to set the new angle:
public class CircleAngleAnimation extends Animation {
private Circle circle;
private float oldAngle;
private float newAngle;
public CircleAngleAnimation(Circle circle, int newAngle) {
this.oldAngle = circle.getAngle();
this.newAngle = newAngle;
this.circle = circle;
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation transformation) {
float angle = oldAngle + ((newAngle - oldAngle) * interpolatedTime);
circle.setAngle(angle);
circle.requestLayout();
}
}
Put circle into your layout:
<com.package.Circle
android:id="@+id/circle"
android:layout_width="300dp"
android:layout_height="300dp" />
And finally starting the animation:
Circle circle = (Circle) findViewById(R.id.circle);
CircleAngleAnimation animation = new CircleAngleAnimation(circle, 240);
animation.setDuration(1000);
circle.startAnimation(animation);
참고URL : https://stackoverflow.com/questions/30958834/circular-reveal-transition-for-new-activity
'Program Tip' 카테고리의 다른 글
SQLite : 인덱스가 범위를 벗어 났기 때문에 인덱스 1에서 인수를 바인딩 할 수 없습니다. (0) | 2020.11.11 |
---|---|
특정 확장자를 가진 파일을 재귀 적으로 찾기 (0) | 2020.11.11 |
Flask @ app.route에서 Python 콘솔로 인쇄하는 방법 (0) | 2020.11.11 |
jinja2 출력을 브라우저 대신 Python으로 파일로 렌더링하는 방법 (0) | 2020.11.10 |
비동기 호출에 대한 JNI 인터페이스 포인터 (JNIEnv *)를 얻는 방법 (0) | 2020.11.10 |