分享

不懂记——对话框动画的右滑进右滑出

 昵称15103532 2013-12-31
layout/activity_animat_dialog.xml
<RelativeLayout xmlns:android="http://schemas./apk/res/android"
    xmlns:tools="http://schemas./tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".AnimatDialogActivity" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dp"
        android:text="@string/hello_world" />
    <Button 
        android:id="@+id/button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dp"
        android:text="点击我弹出对话框"
        />
</RelativeLayout>

values/styles.xml
<resources>
    <style name="mystyle" parent="android:Animation">
        <item name="@android:windowEnterAnimation">@anim/dialog_enter</item>
  <!--进入时的动画     -->
        <item name="@android:windowExitAnimation">@anim/dialog_exit</item>
    <!-- 退出时的动画    -->
</style>
</resources>

anim/dialog_enter.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas./apk/res/android" >
    <!-- %p指相对于父容器 android:fromYDelta="100%p" 
        android:toXDelta="100%p"-->
    <translate
        android:duration="600"
        android:fromXDelta="100%p"
        />
</set>

anim/dialog_exit.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas./apk/res/android" >
    <!-- //持续时间 -->
    <translate
        android:duration="600"
        android:toXDelta="100%" />
</set>

AnimatDialogActivity.java
public class AnimatDialogActivity extends Activity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animat_dialog);
button=(Button) findViewById(R.id.button);
button.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View arg0) {
                // TODO Auto-generated method stub
                AlertDialog dialog = new AlertDialog.Builder(AnimatDialogActivity.this)
                        .setTitle("title").setMessage("message").create();
                Window window = dialog.getWindow();
                window.setGravity(Gravity.LEFT);  //此处可以设置dialog显示的位置
                    window.setWindowAnimations(R.style.mystyle);  //添加动画
                dialog.show();
            }
        });
}
}

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多