簡體   English   中英

DialogFragment中的動畫視圖

[英]Animate view in DialogFragment

好吧,我正在嘗試在DialogFragment中創建一個視圖,並在何時被解除。 但我可以弄明白,它不適合我。 我也嘗試過pepole在這里給出的所有答案。 我試過:onActivityCreate,setStyle(myCustom),oncreate等。

我有一個自定義DialogFragment視圖。 我想在它打開和關閉時為它制作動畫。

真的需要幫助。 謝謝你。

這是我的代碼:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

     inflater = context.getLayoutInflater();
      view = inflater.inflate(R.layout.details_page, container, false);
     //Setting up the image by id
     ImageView img = (ImageView)view.findViewById(R.id.details_img);
     img.setImageResource(this.imageId);
     //Setting up the title
     TextView tittle = (TextView)view.findViewById(R.id.title);
     tittle.setText(this.title);
     tittle.setGravity(Gravity.RIGHT);
     //Setting up all the details about the item
     TextView details = (TextView)view.findViewById(R.id.details);
     details.setText(this.details);
     details.setGravity(Gravity.RIGHT);

     return view;


}

參考你的評論:

我想打開帶有動畫的dialogfragment,比如向上滑動,當用戶返回時也可以向下滑動動畫。

這可能是您的解決方案:

1)創建你喜歡的動畫,即:

/res/anim/slide_up.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
android:shareInterpolator="false" >

    <translate
        android:duration="300"
        android:fromYDelta="100%"
        android:toYDelta="0%"
        android:interpolator="@android:anim/decelerate_interpolator" />

</set>

/res/anim/slide_down.xml

<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:shareInterpolator="false" >

    <translate
        android:duration="300"
        android:fromYDelta="0%"
        android:toYDelta="100%"
        android:interpolator="@android:anim/decelerate_interpolator" />

</set>

2)創建對話框動畫樣式

/res/values/styles.xml

    <!-- [...] -->

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

</resources>

3)將樣式附加到對話框:

@Override
public void onActivityCreated(Bundle arg0) {
    super.onActivityCreated(arg0);
    getDialog().getWindow().getAttributes().windowAnimations = R.style.DialogAnimation;
}

4)完成。 應該管用。

try this . and let me know the updates ...

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View layout = inflater.inflate(R.layout.my_layout, null);

    layMain = (LinearLayout) layout.findViewById(R.id.layMain);

    TextView btnCancel = (TextView) layout.findViewById(R.id.btnCancel);
        btnCancel.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                final Animation anim = AnimationUtils.loadAnimation(getActivity(), R.anim.translate_to_bottom);
                anim.setAnimationListener(new AnimationListener() {

                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        dismiss();
                    }
                });
                layMain.startAnimation(anim);
            }
        });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM