标签:
final Button popup = (Button) findViewById(R.id.button1); //popupwindow JAVA代码部分 popup.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View view = LayoutInflater.from(getApplication()).inflate(R.layout.popuplayout, null); final PopupWindow popupWindow = new PopupWindow(view, //三个属性,视图,高和宽 ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT); popupWindow.setFocusable(true); //必须获取焦点True,否则其他能继续操作就无意义了 popupWindow.showAsDropDown(popup); //设置弹出的位置 ImageView imageView = (ImageView) view.findViewById(R.id.img); imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { popupWindow.dismiss(); } }); } });
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.zhuoxiang.enlightnment.Activity.PopupActivity"> <ImageView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/img" android:src="@drawable/delete"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text" android:text="删除" android:layout_toRightOf="@+id/img"/> </RelativeLayout>
标签:
原文地址:http://www.cnblogs.com/infernofranz/p/5847343.html