实现方法 点击时mPopupWindow.dismiss();
protected void popWindow(View parent) {
// TODO Auto-generated method stubView view = null;
if (mPopupWindow == null) {
LayoutInflater lay = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
view = lay.inflate(R.layout.popbottom, null);
// 初始化按钮
renaming = (TextView) view.findViewById(R.id.pop1);
guanlian = (TextView) view.findViewById(R.id.pop2);
delete = (TextView) view.findViewById(R.id.pop3);
cancle = (TextView) view.findViewById(R.id.pop4);
mPopupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT);
}
// 使窗口里面的空间显示其相应的效果,比较点击button时背景颜色改变。
// 如果为false点击相关的空间表面上没有反应,但事件是可以监听到的。
mPopupWindow.showAtLocation(parent, Gravity.BOTTOM, 0, 0);
mPopupWindow.setAnimationStyle(R.style.popupAnimation);
mPopupWindow.setFocusable(true);
mPopupWindow.setOutsideTouchable(true);
}
popbottom布局文件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/panel_bg"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:orientation="vertical" >
<TextView
android:gravity="center"
android:text="请做出你的选择"
android:textSize="15sp"
android:textColor="@color/text_black"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="fill_parent"
android:background="@drawable/yuankuang2"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:background="@drawable/fengexian2"
/>
<TextView
android:id="@+id/pop1"
android:gravity="center"
android:text="重命名"
android:textColor="#3079B2"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="18sp"
android:layout_width="fill_parent"
android:background="@drawable/yuankuang2"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:background="@drawable/fengexian2"
/>
<TextView
android:id="@+id/pop2"
android:gravity="center"
android:text="关联患者"
android:textColor="#3079B2"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:textSize="18sp"
android:layout_width="fill_parent"
android:background="@drawable/yuankuang2"
android:layout_height="wrap_content"
/>
<ImageView
android:layout_width="fill_parent"
android:layout_height="0.5dp"
android:background="@drawable/fengexian2"
/>
<TextView
android:id="@+id/pop3"
android:gravity="center"
android:text="删除"
android:textColor="#3079B2"
android:textSize="18sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="fill_parent"
android:background="@drawable/yuankuang2"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/pop4"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:gravity="center"
android:text="取消"
android:textColor="#3079B2"
android:textSize="18sp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_width="fill_parent"
android:background="@drawable/yuankuang2"
android:layout_height="wrap_content"
/>
</LinearLayout>
style
popupAnimation
<style name="popupAnimation" parent="android:Animation">
<item name="android:windowEnterAnimation">@anim/pop_translate_in</item>
<item name="android:windowExitAnimation">@anim/pop_translate_out</item>
</style>
anim
in
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:duration="1000"
android:fromYDelta="100%p"
android:toYDelta="60%p" />
</set>
out
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_interpolator" >
<translate
android:duration="1000"
android:fromYDelta="60%p"
android:toYDelta="100%p" />
</set>