1 public class RemindPhotoDialog extends Dialog { 2 3 private final String TAG = "RemindPhotoDialog"; 4 private static int default_width = 280; //默认宽 5 private static int default_height = 440;//默认高度 6 private View upload; 7 private View exit; 8 public static boolean ifDeletedAvatar; 9 10 11 12 public RemindPhotoDialog(Context context, int layout, int theme) { 13 this(context, layout, default_width, default_height, theme); 14 } 15 16 public RemindPhotoDialog(Context context, int layout, int width, int height, int theme) { 17 super(context, theme); 18 setContentView(layout); 19 Window window = getWindow(); 20 WindowManager.LayoutParams params = window.getAttributes(); 21 float density = getDensity(context); 22 // params.width = (int) (width * density); 23 params.width = DeviceUtils.getScreenWidth() - PixelUtils.getPxByDp(32 * 2); 24 // params.width = LinearLayout.LayoutParams.WRAP_CONTENT; 25 params.height = LinearLayout.LayoutParams.WRAP_CONTENT; 26 // params.width = Config.width;//- 35 * density 27 // params.height = (int) (Config.height - 100 * density);//125 28 params.gravity = Gravity.CENTER; 29 window.setAttributes(params); 30 window.setWindowAnimations(R.style.reportDialogWindowAnim); 31 32 initView(); 33 setListener(); 34 } 35 36 37 private void initView() { 38 upload = findViewById(R.id.layout_ok); 39 exit = findViewById(R.id.iv_exit); 40 41 exit.setOnClickListener(new View.OnClickListener() { 42 @Override 43 public void onClick(View v) { 44 dismiss(); 45 } 46 }); 47 upload.setOnClickListener(new View.OnClickListener() { 48 @Override 49 public void onClick(View v) { 50 getContext().startActivity(new Intent(getContext(),MyProfileActivity.class)); 51 ifDeletedAvatar = true; 52 dismiss(); 53 } 54 }); 55 } 56 57 private void setListener() { 58 } 59 60 private float getDensity(Context context) { 61 Resources resources = context.getResources(); 62 DisplayMetrics dm = resources.getDisplayMetrics(); 63 return dm.density; 64 } 65 66 @Override 67 public void show() { 68 super.show(); 69 } 70 71 72 }
2、资源文件
1 <style name="reportDialogWindowAnim" parent="android:Animation"> 2 <item name="android:windowEnterAnimation">@anim/dialog_report_in</item> 3 <item name="android:windowExitAnimation">@anim/dialog_report_out</item> 4 </style>
in
1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3 android:duration="200" 4 android:interpolator="@android:anim/linear_interpolator" > 5 <translate 6 android:fromYDelta="100%p" 7 android:toYDelta="0" /> 8 <alpha 9 android:fromAlpha="0.0" 10 android:toAlpha="1.0" /> 11 12 </set>
out
1 <?xml version="1.0" encoding="utf-8"?> 2 <set xmlns:android="http://schemas.android.com/apk/res/android" 3 android:duration="200" 4 android:interpolator="@android:anim/linear_interpolator"> 5 <translate 6 android:fromYDelta="0" 7 android:toYDelta="100%p" /> 8 <alpha 9 android:fromAlpha="1.0" 10 android:toAlpha="0" /> 11 </set>
style
1 <style name="MyDialogStyle" parent="@android:style/Theme.Dialog"> 2 <item name="android:windowBackground">@color/transparent</item> 3 <item name="android:background">@color/transparent</item> 4 <item name="android:windowFrame">@null</item> 5 <item name="android:windowNoTitle">true</item> 6 <item name="android:windowIsFloating">true</item> 7 <item name="android:windowIsTranslucent">false</item> 8 <item name="android:windowContentOverlay">@null</item> 9 <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 10 <item name="android:backgroundDimEnabled">true</item> 11 <item name="android:backgroundDimAmount">0.5</item> 12 </style>