动画转到顶部后的对话框

时间:2014-02-16 10:00:36

标签: android

我正在创建一个自定义对话框,它将从底部到中心使用动画弹出。一切都很好但是在动画对话框进入屏幕顶部之后。我希望它只在中心。这是我的代码。

 public class CustomDialogClass extends Dialog implements
    android.view.View.OnClickListener {

    public Activity c;
    public Dialog d;
    public Button yes, no;
    private Animation mAnimationBottomCentre;

    public CustomDialogClass(Activity a) {
    super(a,R.style.DialogAnimation);
    // TODO Auto-generated constructor stub
    this.c = a;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.dialog_view);

//  LinearLayout ll = (LinearLayout) findViewById(R.id.mainlayout);
//  mAnimationBottomCentre = AnimationUtils.loadAnimation(c, R.anim.slide_in_left);
//  ll.startAnimation(mAnimationBottomCentre);
    yes = (Button) findViewById(R.id.btn_yes);
    no = (Button) findViewById(R.id.btn_no);
    yes.setOnClickListener(this);
    no.setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
    switch (v.getId()) {
    case R.id.btn_yes:
        c.finish();
        break;
    case R.id.btn_no:
        dismiss();
        break;
    default:
        break;
    }
    dismiss();
    }
}

我正在从我的活动中调用对话框,如下所示:

 public void Show_Dialog(View v) {
CustomDialogClass cdd = new CustomDialogClass(MainActivity.this);
cdd.getWindow().getAttributes().windowAnimations = com.example.chintan.khetiya.android.custom_dialog.R.style.DialogAnimation;
cdd.getWindow().setGravity(Gravity.CENTER);
cdd.show();
}

这是我的动画文件

    <?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true"
    android:interpolator="@android:anim/decelerate_interpolator" >
  <translate
        android:duration="2000"
        android:fillAfter="true"
        android:fromYDelta="100%p"
        android:startOffset="100"
        android:toYDelta="50%p" />
  </set>

这是样式xml

    <style name="DialogAnimation">
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowEnterAnimation">@anim/slide_up_bottom_to_centre</item>
</style>

对话框的布局

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:id="@+id/mainlayout"

    android:layout_height="80dp"
    android:background="#E60000"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/txt_dia"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_margin="10dp"
        android:text="Do you realy want to exit ?"
        android:textColor="@android:color/white"
        android:textSize="15dp"
        android:textStyle="bold" >
    </TextView>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="#3E80B4"
        android:orientation="horizontal" >

        <Button
            android:id="@+id/btn_yes"
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:background="@android:color/white"
            android:clickable="true"
            android:text="Yes"
            android:textColor="#5DBCD2"
            android:textStyle="bold" />

        <Button
            android:id="@+id/btn_no"
            android:layout_width="100dp"
            android:layout_height="30dp"
            android:layout_marginLeft="5dp"
            android:background="@android:color/white"
            android:clickable="true"
            android:text="No"
            android:textColor="#5DBCD2"
            android:textStyle="bold" />
    </LinearLayout>

</LinearLayout>

有人可以帮助如何在中心动画后显示对话框