【问题标题】:Animate view in DialogFragmentDialogFragment 中的动画视图
【发布时间】:2014-06-07 08:26:19
【问题描述】:

好吧,我正在尝试在 DialogFragment 中的视图在创建时和关闭时设置动画。 但我可以弄清楚,它不适合我。 我也尝试了人们在这里给出的所有答案。 我试过: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;


}

【问题讨论】:

    标签: android view dialog android-animation android-dialogfragment


    【解决方案1】:

    参考您的评论:

    我想用向上滑动的动画打开对话框片段,当用户返回时也用向下滑动动画。

    这可能是您的解决方案:

    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) 完成。应该可以。

    【讨论】:

      【解决方案2】:
      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);
                  }
              });
      

      【讨论】:

      • 好吧,我想你没有理解我。我想用向上滑动的动画打开对话框片段,当用户返回时也用向下滑动动画。而且我没有任何按钮可以听,当用户触摸列表中的行时,片段会调用。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多