微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

popuWindow

1,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>

2,popu代码实现

//加载布局

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

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

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

LinearLayoutll_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=newint[2];

view.getLocationInWindow(location);

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。