사용자 정의 대화 상자 애니메이션
텍스트보기에서 아래로 슬라이딩하는 것처럼 사용자 지정 대화 상자를 표시하려고합니다. 이게 가능해? 대화 클래스에 애니메이션을 적용 할 수없는 것 같습니다. 생성자에서이 줄을 시도했지만 효과가 없습니다.
this.getWindow (). setWindowAnimations (R.anim.paranimation);
애니메이션이 옳은지는 확실하지 않지만, 뭘하는지 확인하면 조정할 수 있습니다. 완전성을 위해 아래에 나열하겠습니다. 실제 애니메이션에 대한 도움말이 아니라 대화 상자에 대한 응용 프로그램 만 있습니다.
paranimation.xml :
<?xml version="1.0" encoding="utf-8"?>
<translate
xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="-200%"
android:toXDelta="0%"
android:fromYDelta="200%"
android:toYDelta="0%"
android:duration="3000"
android:zAdjustment="top">
</translate>
나는 오늘 Dialog 애니메이션으로 어려움을 겪고 있었고 마침내 스타일을 사용하여 작동하게되었으므로 여기에 예가 있습니다.
우선, 가장 중요한 것은 아마도 오늘 5 가지 다른 방식으로 작동했지만 알 수 없었습니다. 장치 애니메이션 설정이 "애니메이션 없음"(설정 → 디스플레이 → 애니메이션)으로 설정되어 있으면 대화 상자가 이겼습니다. 당신이 무엇을하든 애니메이션되지 마십시오!
다음은 내 styles.xml의 제거 된 버전입니다. 자명하기를 바랍니다. 이 위치는 res/values
.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="PauseDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
</style>
<style name="PauseDialogAnimation">
<item name="android:windowEnterAnimation">@anim/spin_in</item>
<item name="android:windowExitAnimation">@android:anim/slide_out_right</item>
</style>
</resources>
는 windowEnterAnimation
내 애니메이션 중 하나입니다에 위치하고 있습니다 res\anim
. 는 windowExitAnimation
안드로이드 SDK의 일부인 애니메이션 중 하나입니다.
그런 다음 내 활동 onCreateDialog(int id)
방법 에서 대화 상자를 만들 때 다음을 수행합니다.
Dialog dialog = new Dialog(this, R.style.PauseDialog);
// Setting the title and layout for the dialog
dialog.setTitle(R.string.pause_menu_label);
dialog.setContentView(R.layout.pause_menu);
또는 테마를 사용하는 Dialog 생성자를 사용하는 대신 다음과 같은 방법으로 애니메이션을 설정할 수 있습니다.
Dialog dialog = new Dialog(this);
dialog.getWindow().getAttributes().windowAnimations = R.style.PauseDialogAnimation;
I have created the Fade in and Fade Out animation for Dialogbox using ChrisJD code.
Inside res/style.xml
<style name="AppTheme" parent="android:Theme.Light" /> <style name="PauseDialog" parent="@android:style/Theme.Dialog"> <item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item> </style> <style name="PauseDialogAnimation"> <item name="android:windowEnterAnimation">@anim/fadein</item> <item name="android:windowExitAnimation">@anim/fadeout</item> </style>
Inside anim/fadein.xml
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="500" />
Inside anim/fadeut.xml
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/anticipate_interpolator" android:fromAlpha="1.0" android:toAlpha="0.0" android:duration="500" />
MainActivity
Dialog imageDiaglog= new Dialog(MainActivity.this,R.style.PauseDialog);
For right to left (entry animation) and left to right (exit animation):
styles.xml:
<style name="CustomDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">@style/CustomDialogAnimation</item>
</style>
<style name="CustomDialogAnimation">
<item name="android:windowEnterAnimation">@anim/translate_left_side</item>
<item name="android:windowExitAnimation">@anim/translate_right_side</item>
</style>
Create two files in res/anim/:
translate_right_side.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%" android:toXDelta="100%"
android:fromYDelta="0%" android:toYDelta="0%"
android:duration="600"/>
translate_left_side.xml:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="600"
android:fromXDelta="100%"
android:toXDelta="0%"/>
In you Fragment/Activity:
Dialog dialog = new Dialog(getActivity(), R.style.CustomDialog);
I meet the same problem,but ,at last I solve the problem by followed way
((ViewGroup)dialog.getWindow().getDecorView())
.getChildAt(0).startAnimation(AnimationUtils.loadAnimation(
context,android.R.anim.slide_in_left));
First you have to create two animation resources in res/anim
slide_up.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromydelta="100%"
android:interpolator="@android:anim/accelerate_interpolator"
android:toxdelta="0">
</translate>
slide_bottom.xml
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="@android:integer/config_mediumAnimTime"
android:fromydelta="0%p"
android:interpolator="@android:anim/accelerate_interpolator"
android:toydelta="100%p">
</translate>
then you have to create a style
<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_up</item>
<item name="android:windowExitAnimation">@anim/slide_bottom</item>
</style>
and add this line to your class
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
Based in http://www.devexchanges.info/2015/10/showing-dialog-with-animation-in-android.html
Try below code:
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));// set transparent in window background
View _v = inflater.inflate(R.layout.some_you_layout, container, false);
//load animation
//Animation transition_in_view = AnimationUtils.loadAnimation(getContext(), android.R.anim.fade_in);// system animation appearance
Animation transition_in_view = AnimationUtils.loadAnimation(getContext(), R.anim.customer_anim);//customer animation appearance
_v.setAnimation( transition_in_view );
_v.startAnimation( transition_in_view );
//really beautiful
return _v;
}
Create the custom Anim.: res/anim/customer_anim.xml:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="500"
android:fromYDelta="100%"
android:toYDelta="-7%"/>
<translate
android:duration="300"
android:startOffset="500"
android:toYDelta="7%" />
<translate
android:duration="200"
android:startOffset="800"
android:toYDelta="0%" />
</set>
참고URL : https://stackoverflow.com/questions/4817014/animate-a-custom-dialog
'code' 카테고리의 다른 글
PHPExcel 자동 크기 열 너비 (0) | 2020.08.31 |
---|---|
외부 어셈블리에서 내부 클래스에 액세스하려면 어떻게해야합니까? (0) | 2020.08.31 |
커밋 메시지에 Git의 브랜치 이름을 추가하는 방법은 무엇입니까? (0) | 2020.08.31 |
5 초마다 Javascript 함수를 지속적으로 호출 (0) | 2020.08.31 |
데이터 세트에서 특이 치를 제거하는 방법 (0) | 2020.08.31 |