想让弹出的PPwindow 实现如下效果!
图片说明
xml布局:
<?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="#00000000"
android:orientation="vertical"
android:padding="10dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/circle_while_bg"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="投诉"
android:textColor="@color/text_red"
android:textSize="20sp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:background="@drawable/circle_while_bg"
android:gravity="center"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:text="取消"
android:textColor="@color/text_lan"
android:textSize="20sp" />
</LinearLayout>
代码显示PPwindow:
View contentView = LayoutInflater.from(MainActivity.this).inflate(R.layout.activity_test, null);
final PopupWindow popupWindow = new PopupWindow(contentView, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
popupWindow.setBackgroundDrawable(new BitmapDrawable());
popupWindow.setAnimationStyle(R.style.anim_popup_dir);
popupWindow.setOutsideTouchable(true);
popupWindow.setFocusable(true);
WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.alpha = 0.5f;
getWindow().setAttributes(lp);
popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
@Override
public void onDismiss() {
WindowManager.LayoutParams lp=getWindow().getAttributes();
lp.alpha = 1f;
getWindow().setAttributes(lp);
}
});
popupWindow.showAtLocation(getWindow().getDecorView(), Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);