您的位置:首页 > 其它

由下至上弹出并位于屏幕底部的提示框

2013-05-05 00:37 435 查看
androidencodinganimationdialog

[java]
view plaincopyprint?

button.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {

// TODO Auto-generated method stub

AlertDialog dialog = new AlertDialog.Builder(TestAndroid1Activity.this)

.setTitle("title").setMessage("message").create();

Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM); //此处可以设置dialog显示的位置

window.setWindowAnimations(R.style.mystyle);
//添加动画
dialog.show();
}
);

button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
AlertDialog dialog = new AlertDialog.Builder(TestAndroid1Activity.this)
.setTitle("title").setMessage("message").create();
Window window = dialog.getWindow();
window.setGravity(Gravity.BOTTOM);  //此处可以设置dialog显示的位置
window.setWindowAnimations(R.style.mystyle);  //添加动画
dialog.show();
}
});

styles.xml

[java]
view plaincopyprint?

<?xml version="1.0" encoding="utf-8"?>

<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>

<?xml version="1.0" encoding="utf-8"?>
<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>


位于 res/anim/dialog_enter.xml

[java]
view plaincopyprint?

<?xml version="1.0" encoding="utf-8"?>

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

<translate
android:fromYDelta="100%p" %p指相对于父容器

android:duration="600"

/>
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate
android:fromYDelta="100%p"       %p指相对于父容器
android:duration="600"
/>
</set>


位于 res/anim/dialog_exit.xml

[java]
view plaincopyprint?

<?xml version="1.0" encoding="utf-8"?>

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

<translate
android:toYDelta="100%p"

android:duration="600"
//持续时间
/>
</set>

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">

<translate
android:toYDelta="100%p"
android:duration="600"    //持续时间
/>
</set>


此处只是做了垂直位移的效果,自己还可以试试别的效果。

<alpha /> 透明度

<rotate /> 旋转

<scale /> 缩放
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: