赞
踩
android 自定义对话框使对话框铺满全屏。边缘无缝对接,
效果图如下:
调用方式:
new AdFullDialog(MainActivity.this, “”, “”, “”, “”).show();
对话框代码:
- /**
- * 全屏广告
- */
- public class AdFullDialog extends Dialog {
- private Context context;
-
- private String mUrl;
-
- Bitmap bmp;
-
- String mtarget_url;
-
- String Target_url;
-
-
- ImageView ivAdvertising;
- TextView mtv_second;
- LinearLayout layout_skip;
-
- public AdFullDialog(Context context, String url, String target_url, String Deep_link, List<String> deep_link_monitor_url) {
- // 更改样式,把背景设置为透明的
- super(context, R.style.dialog);
- this.context = context;
- mUrl = url;
- mtarget_url = target_url;
- Log.e("getTarget_url111", mtarget_url);
- }
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- calculateHeightAndWidth();
- }
-
- @Override
- public void show() {
- super.show();
- /**
- * 设置宽度全屏,要设置在show的后面
- */
- WindowManager.LayoutParams layoutParams = getWindow().getAttributes();
- layoutParams.gravity = Gravity.BOTTOM;
- layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
- layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT;
-
- getWindow().getDecorView().setPadding(0, 0, 0, 0);
-
- getWindow().setAttributes(layoutParams);
- }
-
- /**
- * 按实际图片比例对其的宽高进行缩放
- */
- private void calculateHeightAndWidth() {
- initAdView();
-
- }
-
- @SuppressLint("ResourceType")
- private void initAdView() {
- new Thread(getPicByUrl).start();//获取图片
-
- setContentView(R.layout.activity_ad);//加载自定义布局
-
- ivAdvertising = findViewById(R.id.iv_advertising);
- layout_skip = findViewById(R.id.layout_skip_close);
- mtv_second = findViewById(R.id.tv_second);
- ivAdvertising.setOnTouchListener(new TouchListenerImp());
- ivAdvertising.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });
- layout_skip.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- dismiss();
- }
- });
- }
-
-
- Runnable getPicByUrl = new Runnable() {
- @Override
- public void run() {
- try {
- bmp = GetImgUtil.getImage(mUrl);// BitmapFactory:图片工厂!
- Log.i("ggggg", bmp.toString());
- sendMsg(1);
- } catch (Exception e) {
- Log.i("ggggg", e.getMessage());
- }
- }
- };
-
-
-
-
- /**
- * 获取点击对话框坐标
- */
- private class TouchListenerImp implements View.OnTouchListener {
-
- public boolean onTouch(View v, MotionEvent event) {
-
- ClickXY clickXY = new ClickXY();
- NumberFormat nf = new DecimalFormat("#.#");
- double a = 3.1;
-
- SLOT_X = nf.format(event.getX());
- SLOT_Y = nf.format(event.getY());
- // Log.e("LZ", "---SLOT_X=" + event.getRawX() + "----SLOT_X=" + event.getRawY())
-
- DOWN_X = nf.format(event.getRawX());
- DOWN_Y = nf.format(event.getRawY());
- clickXY.setSLOT_X(SLOT_X);
- clickXY.setSLOT_Y(SLOT_Y);
- clickXY.setDOWN_X(DOWN_X);
- clickXY.setDOWN_Y(DOWN_Y);
- Log.e("LZ", "---SLOT_X=" + event.getRawX() + "----SLOT_X=" + event.getRawY() + "DOWN_X=" + DOWN_X + "DOWN_Y=" + DOWN_Y);
-
- return false;
- }
- }
- }

XML文件:
- <?xml version="1.0" encoding="utf-8"?>
- <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:fitsSystemWindows="true"
- android:orientation="vertical">
-
- <ImageView
- android:id="@+id/iv_advertising"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_gravity="center_horizontal"
- android:visibility="gone"
- android:scaleType="fitXY"
- />
-
- <LinearLayout
- android:id="@+id/layout_skip_close"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right"
- android:layout_marginRight="8dp"
- android:layout_marginTop="40dp"
- android:background="@drawable/splash_skip"
- android:orientation="horizontal"
-
- android:padding="4dp"
- android:visibility="visible">
-
- <TextView
- android:id="@+id/tv_second"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right"
- android:paddingLeft="5dp"
- android:text=" "
- android:visibility="visible"
- android:textColor="@color/colorWhite"
- android:textSize="16sp" />
-
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="right"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:text=""
- android:textColor="@color/colorWhite"
- android:textSize="16sp" />
- </LinearLayout>
- </FrameLayout>

-END
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。