gpt4 book ai didi

android - 设置 Android fragment 进入和退出转换?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:33:08 25 4
gpt4 key购买 nike

我正在尝试为 DialogFragment 设置进入和退出过渡,这看起来很简单。这是我的 DrinkDetailActivity 创建对话框的代码:

    fab.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
//create and display the dialog
DialogFragment orderFragment = new OrderDrinkDialogFragment();

//set the slide transition for the fragment
Transition dialSlide = new Slide();
dialSlide.setDuration(300);

orderFragment.setEnterTransition(dialSlide);
orderFragment.setExitTransition(dialSlide);
orderFragment.show(getFragmentManager(), "order");
}
});

这是来 self 的 OrderDrinkDialogFragment 类的代码:

public class OrderDrinkDialogFragment extends DialogFragment
{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder builder = new AlertDialog.Builder(DrinkDetailActivity.activity);

//set up the Linear Layout of the dialog
LinearLayout layout = new LinearLayout(DrinkDetailActivity.activity);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
layout.setOrientation(LinearLayout.VERTICAL);
layout.setLayoutParams(params);

//set up the EditText view
EditText nameField = new EditText(DrinkDetailActivity.activity);
nameField.setHint(R.string.dialog_name_hint);

//add the EditText view to the layout
layout.addView(nameField, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT));

//set layout as the view of the dialog
builder.setView(layout);

return builder.create();
}
}

DrinkDetailActivity.activity 只是 DrinkDetailActivity 实例中的 this。出于某种原因,当我 show() 或关闭对话框时,对话框不会转换,它只是在 View 中弹出和弹出。 This教程对我确定应用程序其余部分的 Activity 转换有很大帮助,并且我遵循了与它所说的相同的 fragment 转换说明。我做错了什么?

最佳答案

这对我有用。我的向上滑动动画是

<?xml version="1.0" encoding="utf-8"?> <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" />

</set>

我的幻灯片动画是

<?xml version="1.0" encoding="utf-8"?>
<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" />

</set>

在你的样式中添加这个

<style name="DialogAnimation">
<item name="android:windowEnterAnimation">@anim/slide_up</item>
<item name="android:windowExitAnimation">@anim/slide_down</item>
</style>

现在终于在 Dialog fragment 的 onCreateDialog() 中添加这个

public Dialog onCreateDialog(Bundle savedInstanceState) 
{
final Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
return dialog;
}

关于android - 设置 Android fragment 进入和退出转换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28450083/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com