加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

popuWindow

发布时间:2020-12-16 09:17:56 所属栏目:百科 来源:网络整理
导读:popuWindow X ml布局 ? xml version = "1.0" encoding = "utf-8" ? LinearLayout xmlns:android = "http://schemas.android.com/apk/res/android" android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:background = "@dr

popuWindow

Xml布局

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="@drawable/local_popup_bg"

android:orientation="horizontal" >

<!-- 拨打电话 -->

<LinearLayout

android:id="@+id/ll_call"

android:layout_width="40dip"

android:layout_height="wrap_content"

android:orientation="vertical" >

<ImageView

android:layout_width="40dip"

android:layout_height="wrap_content"

android:src="@android:drawable/ic_menu_call" />

<TextView

android:layout_width="40dip"

android:layout_height="wrap_content"

android:gravity="center"

android:text="电话" />

</LinearLayout>

<!-- 发送短信 -->

<LinearLayout

android:id="@+id/ll_sms"

android:layout_width="40dip"

android:layout_height="wrap_content"

android:layout_marginLeft="10dip"

android:orientation="vertical" >

<ImageView

android:layout_width="40dip"

android:layout_height="wrap_content"

android:src="@android:drawable/ic_menu_send" />

<TextView

android:layout_width="40dip"

android:layout_height="wrap_content"

android:gravity="center"

android:text="短信" />

</LinearLayout>

</LinearLayout>

Popu 代码实现

//加载布局

View contentView=View.inflate(getApplicationContext(),R.layout.popu_dialog,null);

//找到相应的控件进行操作1,拨打电话,2,发送短信

LinearLayout ll_call=(LinearLayout)contentView.findViewById(R.id.ll_call);

LinearLayout ll_sms=(LinearLayout) contentView.findViewById(R.id.ll_sms);

//弹出popu对话框

pw=new PopupWindow(contentView,LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);

//背景透明

pw.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

//宽,高的数组

int[] location=new int[2];

view.getLocationInWindow(location);

pw.showAtLocation(view,Gravity.LEFT|Gravity.TOP,30,location[1]);

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读