在动画 onCreate 中滑动 android
slide in animantion onCreate android
我试图在创建 activity 后立即滑入自定义对话框。但每次对话都伴随着 activity。我想在 activity 创建后显示对话框。
已尝试在 onCreate()
、onResume
、onPostResume
.
中创建对话框
对话框创建:
Dialog dialog = new Dialog(this, R.style.PauseDialog);
dialog.setTitle("Test Dialog Transition");
dialog.show();
动画风格:
<style name="PauseDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
</style>
<style name="PauseDialogAnimation">
<item name="android:windowEnterAnimation">@android:anim/slide_in_left</item>
<item name="android:windowExitAnimation">@android:anim/slide_out_right</item>
</style>
更新答案以包含一个布尔值以确定我们是否已显示该对话框以避免多次显示。
这似乎工作正常。
Called when the current Window of the activity gains or loses focus. This is the best indicator of whether this activity is visible to the user.
boolean mDialogShown = false;
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
if(!mDialogShown)
{
mDialogShown = true;
Dialog dialog = new Dialog(this, R.style.PauseDialog);
dialog.setTitle("Test Dialog Transition");
dialog.show();
}
super.onWindowFocusChanged(hasFocus);
}
我能找到的延迟转换的最佳方法是使用 Handler。我使用 postDelayed() 来延迟对话框的转换。
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Dialog dialog = new Dialog(MainActivity.this, R.style.PauseDialog);
dialog.setTitle("Test Dialog Transition");
dialog.show();
}
}, 1000);
我试图在创建 activity 后立即滑入自定义对话框。但每次对话都伴随着 activity。我想在 activity 创建后显示对话框。
已尝试在 onCreate()
、onResume
、onPostResume
.
对话框创建:
Dialog dialog = new Dialog(this, R.style.PauseDialog);
dialog.setTitle("Test Dialog Transition");
dialog.show();
动画风格:
<style name="PauseDialog" parent="@android:style/Theme.Dialog">
<item name="android:windowAnimationStyle">@style/PauseDialogAnimation</item>
</style>
<style name="PauseDialogAnimation">
<item name="android:windowEnterAnimation">@android:anim/slide_in_left</item>
<item name="android:windowExitAnimation">@android:anim/slide_out_right</item>
</style>
更新答案以包含一个布尔值以确定我们是否已显示该对话框以避免多次显示。
这似乎工作正常。
Called when the current Window of the activity gains or loses focus. This is the best indicator of whether this activity is visible to the user.
boolean mDialogShown = false;
@Override
public void onWindowFocusChanged(boolean hasFocus)
{
if(!mDialogShown)
{
mDialogShown = true;
Dialog dialog = new Dialog(this, R.style.PauseDialog);
dialog.setTitle("Test Dialog Transition");
dialog.show();
}
super.onWindowFocusChanged(hasFocus);
}
我能找到的延迟转换的最佳方法是使用 Handler。我使用 postDelayed() 来延迟对话框的转换。
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Dialog dialog = new Dialog(MainActivity.this, R.style.PauseDialog);
dialog.setTitle("Test Dialog Transition");
dialog.show();
}
}, 1000);