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

    xiaoxiao2026-05-02  8

    来源: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 />        缩放

    转载请注明原文地址: https://ju.6miu.com/read-1309291.html
    最新回复(0)