android 实现由下至上弹出并位于屏幕底部的提示框
2016-08-16 14:45
465 查看
来源:http://blog.csdn.net/centralperk/article/details/7494441[java] view
plain copy
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
plain copy
<?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
plain copy
<?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
plain copy
<?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 /> 缩放
plain copy
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
plain copy
<?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
plain copy
<?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
plain copy
<?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 /> 缩放
相关文章推荐
- android 实现由下至上弹出并位于屏幕底部的提示框
- android 实现由下至上弹出并位于屏幕底部的提示框
- Android 实现由下至上弹出并位于屏幕底部的提示框
- android 实现由下至上弹出并位于屏幕底部的提示框
- Android 实现由下至上弹出并位于屏幕底部的提示框
- android 实现由下至上弹出并位于屏幕底部的提示框
- Android 实现由下至上弹出并位于屏幕底部的提示框
- android 实现由下至上弹出并位于屏幕底部的提示框
- android 实现由下至上弹出并位于屏幕底部的提示框【转】
- android 实现由下至上弹出并位于屏幕底部的Dialog
- android 实现由下至上弹出并位于屏幕底部的提示框
- 由下至上弹出并位于屏幕底部的提示框
- 实现底部的弹出框(官方API实现Android的在屏幕中间)
- Android 实现屏幕底部弹出Dialog
- Android底部菜单布局+PopupWindows实现弹出菜单功能(初级篇)
- android Activity实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- 【Android UI设计与开发】7.底部菜单栏(四)PopupWindow 实现显示仿腾讯新闻底部弹出菜单
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口
- android PopupWindow实现从底部弹出或滑出选择菜单或窗口