2015-12-03 53 views
-1

我在20秒後在主要活動中創建了一個彈出窗口。我在我的用戶界面的右上角有一個小的imageview。我希望我的彈出窗口來自該圖像(如動畫或縮放圖像中的閃光並顯示彈出窗口)。我怎樣才能做到這一點?希望你明白我想問什麼。這是我在MainActivity類中完成的彈出代碼。在android中彈出的動畫

Handler handler = new Handler(); 

     handler.postDelayed(new Runnable() { 

      @Override 

      public void run() { 

       new AlertDialog.Builder(context) 
         .setTitle("Win Free Recharge") 
         .setMessage("Do you want to earn free recharge?") 
         .setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int which) { 
           // continue with delete 
           Intent intent = new Intent(MainActivity.this, WebActivity.class); 
           startActivity(intent); 
          } 
         }) 
         .setNegativeButton(R.string.no, new DialogInterface.OnClickListener() { 
          public void onClick(DialogInterface dialog, int which) { 
           // do nothing 
          } 
         }) 
         .setIcon(R.drawable.inr1) 
         .show(); 
      } 
     }, 20000); 

回答

0

在你的風格

<style name="MyAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert"> 
     <item name="android:windowEnterAnimation">@anim/anim_scale_in</item> 
     <item name="android:windowExitAnimation">@anim/anim_scale_out</item> 
     <item name="colorAccent">@color/colorPrimary</item> 
</style> 
在動畫文件夾

添加此樣式屬性,創建anim_scale_in.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <scale 
     android:duration="@android:integer/config_shortAnimTime" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:fromXScale="0.7" 
     android:toXScale="1.0" 
     android:fromYScale="0.7" 
     android:toYScale="1.0"/> 

    <alpha 
     android:duration="@android:integer/config_shortAnimTime" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:fromAlpha="0" 
     android:toAlpha="1.0"/> 
</set> 
在動畫文件夾

,創建anim_scale_out.xml

<?xml version="1.0" encoding="utf-8"?> 
<set xmlns:android="http://schemas.android.com/apk/res/android"> 
    <scale 
     android:duration="@android:integer/config_shortAnimTime" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:fromXScale="1.0" 
     android:toXScale="0.7" 
     android:fromYScale="1.0" 
     android:toYScale="0.7"/> 

    <alpha 
     android:duration="@android:integer/config_shortAnimTime" 
     android:interpolator="@android:interpolator/accelerate_decelerate" 
     android:fromAlpha="1.0" 
     android:toAlpha="0.0"/> 

</set> 

使用以下代碼在對話框中應用動畫:

AlertDialog.Builder alert = new AlertDialog.Builder(mContext, R.style.MyAlertDialogStyle) 
         .setTitle("Title") 
         .setMessage("Message") 
         .setPositiveButton("OK", new DialogInterface.OnClickListener() { 
          @Override 
          public void onClick(DialogInterface dialog, int which) { 

          } 
         }).setNegativeButton("CANCEL", new DialogInterface.OnClickListener() { 
          @Override 
          public void onClick(DialogInterface dialogInterface, int i) { 
           dialogInterface.dismiss(); 
          } 
         }); 
       Dialog mDialog = alert.create(); 
       mDialog.getWindow().getAttributes().windowAnimations = R.style.MyAlertDialogStyle; 
       mDialog.show(); 
+0

Thanks!彈出對話框很好,但我的主要問題是我怎樣才能從我的用戶界面右上角的圖像視圖。我希望我的彈出窗口來自該圖像的閃光燈。這裏只是在一段時間後纔出現。請幫忙!!! –