如何使用动画重新调整对话框的大小

时间:2015-01-05 07:31:04

标签: android animation dialog

我在对话框xml布局中创建了一个自定义对话框类(extends Dialog) 我用动画扩展/折叠textview,这工作正常, 但是当我展开或折叠视图(文本视图)时,对话框的大小也会改变(没有动画),如何使它也能用动画重新调整大小?

public class ErrorDialog extends Dialog {

private String err;
private  TextView  txt_help_gest;


 public ErrorDialogOnClickListener errorDialogListener;
 private String shortDesc;

private Animation slide_up_Animation;
private Animation slide_down_Animation;

private Animation rotate_arrow_down;
private Animation rotate_arrow_up;

public ErrorDialog(Context context,String shortDesc, String err, ErrorDialogOnClickListener errorDialogListener) {
    super(context);
    this.err=err;
    this.errorDialogListener = errorDialogListener;
    this.shortDesc=shortDesc;

    slide_up_Animation= AnimationUtils.loadAnimation(context, R.anim.slide_up);
    slide_down_Animation= AnimationUtils.loadAnimation(context, R.anim.slide_down);

    rotate_arrow_down= AnimationUtils.loadAnimation(context, R.anim.rotate_arrow_down);
    rotate_arrow_up= AnimationUtils.loadAnimation(context, R.anim.rotate_arrow_up);
    getWindow().getAttributes().windowAnimations = R.style.Animations_SmileWindow;

}
@Override
public void onCreate(Bundle savedInstanceState) {


    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_error);

    setTitle("שגיאה");
    setCancelable(false);
    // set values for custom dialog components - text, image and button
    Button btnClose=(Button)findViewById(R.id.btnClose);
    TextView text = (TextView) findViewById(R.id.textDialog);
    txt_help_gest = (TextView) findViewById(R.id.txt_help_gest);
    //help_title_gest = (TextView) findViewById(R.id.help_title_gest);
    final ImageView imgArrow = (ImageView) findViewById(R.id.imgArrow);
    LinearLayout ll_help_title = (LinearLayout) findViewById(R.id.ll_help_title);


   // ll = (View) findViewById(R.id.ll);
    text.setText(shortDesc+"\n התוכנית תסגר.");
    txt_help_gest.setText(err);

    txt_help_gest.setVisibility(View.GONE);


    ll_help_title.setOnClickListener(new android.view.View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            //txt_help_gest.clearAnimation();

            if(txt_help_gest.isShown()){
                 //collapse();
                //slide_up_Animation.reset();
                 txt_help_gest.startAnimation(slide_up_Animation);

                txt_help_gest.setVisibility(View.GONE);

                imgArrow.startAnimation(rotate_arrow_up);

              }
              else{
                 // expand();
                //  slide_down_Animation.reset();
                txt_help_gest.setVisibility(View.VISIBLE);
                txt_help_gest.startAnimation(slide_down_Animation);
                imgArrow.startAnimation(rotate_arrow_down);
              }

        }
    });
    btnClose.setOnClickListener(new android.view.View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            errorDialogListener.onButtonClick();  
            dismiss();
        }
    });

}
 public interface ErrorDialogOnClickListener {
        void onButtonClick();
    }

}

0 个答案:

没有答案