当前位置:   article > 正文

Android对话框图片全屏_android dialog 图片占满

android dialog 图片占满

 android 自定义对话框使对话框铺满全屏。边缘无缝对接,

效果图如下:

调用方式:

 new AdFullDialog(MainActivity.this, “”, “”, “”, “”).show();

 对话框代码:

  1. /**
  2. * 全屏广告
  3. */
  4. public class AdFullDialog extends Dialog {
  5. private Context context;
  6. private String mUrl;
  7. Bitmap bmp;
  8. String mtarget_url;
  9. String Target_url;
  10. ImageView ivAdvertising;
  11. TextView mtv_second;
  12. LinearLayout layout_skip;
  13. public AdFullDialog(Context context, String url, String target_url, String Deep_link, List<String> deep_link_monitor_url) {
  14. // 更改样式,把背景设置为透明的
  15. super(context, R.style.dialog);
  16. this.context = context;
  17. mUrl = url;
  18. mtarget_url = target_url;
  19. Log.e("getTarget_url111", mtarget_url);
  20. }
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. requestWindowFeature(Window.FEATURE_NO_TITLE);
  25. calculateHeightAndWidth();
  26. }
  27. @Override
  28. public void show() {
  29. super.show();
  30. /**
  31. * 设置宽度全屏,要设置在show的后面
  32. */
  33. WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
  34. layoutParams.gravity = Gravity.BOTTOM;
  35. layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
  36. layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
  37. getWindow().getDecorView().setPadding(0, 0, 0, 0);
  38. getWindow().setAttributes(layoutParams);
  39. }
  40. /**
  41. * 按实际图片比例对其的宽高进行缩放
  42. */
  43. private void calculateHeightAndWidth() {
  44. initAdView();
  45. }
  46. @SuppressLint("ResourceType")
  47. private void initAdView() {
  48. new Thread(getPicByUrl).start();//获取图片
  49. setContentView(R.layout.activity_ad);//加载自定义布局
  50. ivAdvertising = findViewById(R.id.iv_advertising);
  51. layout_skip = findViewById(R.id.layout_skip_close);
  52. mtv_second = findViewById(R.id.tv_second);
  53. ivAdvertising.setOnTouchListener(new TouchListenerImp());
  54. ivAdvertising.setOnClickListener(new View.OnClickListener() {
  55. @Override
  56. public void onClick(View view) {
  57. }
  58. });
  59. layout_skip.setOnClickListener(new View.OnClickListener() {
  60. @Override
  61. public void onClick(View view) {
  62. dismiss();
  63. }
  64. });
  65. }
  66. Runnable getPicByUrl = new Runnable() {
  67. @Override
  68. public void run() {
  69. try {
  70. bmp = GetImgUtil.getImage(mUrl);// BitmapFactory:图片工厂!
  71. Log.i("ggggg", bmp.toString());
  72. sendMsg(1);
  73. } catch (Exception e) {
  74. Log.i("ggggg", e.getMessage());
  75. }
  76. }
  77. };
  78. /**
  79. * 获取点击对话框坐标
  80. */
  81. private class TouchListenerImp implements View.OnTouchListener {
  82. public boolean onTouch(View v, MotionEvent event) {
  83. ClickXY clickXY = new ClickXY();
  84. NumberFormat nf = new DecimalFormat("#.#");
  85. double a = 3.1;
  86. SLOT_X = nf.format(event.getX());
  87. SLOT_Y = nf.format(event.getY());
  88. // Log.e("LZ", "---SLOT_X=" + event.getRawX() + "----SLOT_X=" + event.getRawY())
  89. DOWN_X = nf.format(event.getRawX());
  90. DOWN_Y = nf.format(event.getRawY());
  91. clickXY.setSLOT_X(SLOT_X);
  92. clickXY.setSLOT_Y(SLOT_Y);
  93. clickXY.setDOWN_X(DOWN_X);
  94. clickXY.setDOWN_Y(DOWN_Y);
  95. Log.e("LZ", "---SLOT_X=" + event.getRawX() + "----SLOT_X=" + event.getRawY() + "DOWN_X=" + DOWN_X + "DOWN_Y=" + DOWN_Y);
  96. return false;
  97. }
  98. }
  99. }

XML文件:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:fitsSystemWindows="true"
  6. android:orientation="vertical">
  7. <ImageView
  8. android:id="@+id/iv_advertising"
  9. android:layout_width="match_parent"
  10. android:layout_height="match_parent"
  11. android:layout_gravity="center_horizontal"
  12. android:visibility="gone"
  13. android:scaleType="fitXY"
  14. />
  15. <LinearLayout
  16. android:id="@+id/layout_skip_close"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:layout_gravity="right"
  20. android:layout_marginRight="8dp"
  21. android:layout_marginTop="40dp"
  22. android:background="@drawable/splash_skip"
  23. android:orientation="horizontal"
  24. android:padding="4dp"
  25. android:visibility="visible">
  26. <TextView
  27. android:id="@+id/tv_second"
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:layout_gravity="right"
  31. android:paddingLeft="5dp"
  32. android:text=" "
  33. android:visibility="visible"
  34. android:textColor="@color/colorWhite"
  35. android:textSize="16sp" />
  36. <TextView
  37. android:layout_width="wrap_content"
  38. android:layout_height="wrap_content"
  39. android:layout_gravity="right"
  40. android:paddingLeft="5dp"
  41. android:paddingRight="5dp"
  42. android:text=""
  43. android:textColor="@color/colorWhite"
  44. android:textSize="16sp" />
  45. </LinearLayout>
  46. </FrameLayout>

                                                                                                                                                                    -END

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/知新_RL/article/detail/318511
推荐阅读
相关标签
  

闽ICP备14008679号