Android 實現由下至上彈出並位於屏幕底部的提示框





 


Android 實現由下至上彈出並位於屏幕底部的提示框:
              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

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

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

<?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 />        縮放


發佈了18 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章