/****
* 头像提示框
*/
public void showPopupWindow() {
pop = new PopupWindow(getContext());
View view = LayoutInflater.from(getContext()).inflate(R.layout.item_popupwindows,
null);
ll_popup = (LinearLayout) view.findViewById(R.id.ll_popup);
pop.setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
pop.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);
pop.setBackgroundDrawable(new BitmapDrawable());
HelpUtils.setBackGroundAlpha(pop, getActivity());
pop.setFocusable(true);
pop.setOutsideTouchable(true);
pop.setContentView(view);
RelativeLayout parent = (RelativeLayout) view.findViewById(R.id.parent);
Button bt1 = (Button) view.findViewById(R.id.item_popupwindows_camera);
Button bt2 = (Button) view.findViewById(R.id.item_popupwindows_Photo);
Button bt3 = (Button) view.findViewById(R.id.item_popupwindows_cancel);
parent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getCamera();
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
getPhoto();
pop.dismiss();
ll_popup.clearAnimation();
}
});
bt3.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
pop.dismiss();
ll_popup.clearAnimation();
}
});
}
xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:background="@android:color/transparent">
<LinearLayout
android:id="@+id/ll_popup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:paddingBottom="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/border_while_roval"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#e4e4e4" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal">
<Button
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="@drawable/bt_nobgd"
android:clickable="false"
android:text="选择照片"
android:textColor="#585858"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#e4e4e4" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal">
<Button
android:id="@+id/item_popupwindows_camera"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="@drawable/bt_nobgd"
android:text="拍照"
android:textColor="#0066CC"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#e4e4e4" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:orientation="horizontal">
<Button
android:id="@+id/item_popupwindows_Photo"
android:layout_width="match_parent"
android:layout_height="55dp"
android:background="@drawable/bt_nobgd"
android:text="从相册中选择"
android:textColor="#0066CC"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#e4e4e4" />
</LinearLayout>
<Button
android:id="@+id/item_popupwindows_cancel"
android:layout_width="match_parent"
android:layout_height="55dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="@drawable/border_while_roval"
android:text="取消"
android:textColor="#0066CC"
android:textSize="18sp" />
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<!-- activity显示时的平移动画 -->
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="150"
android:fromYDelta="100%"
android:toYDelta="0%"
android:interpolator="@android:anim/accelerate_decelerate_interpolator" >
</translate>
调用
//setUserAvater();
showPopupWindow();
ll_popup.startAnimation(AnimationUtils.loadAnimation(
getContext(), R.anim.activity_translate_in));
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<solid android:color="#FFFFFF" />
<corners
android:bottomLeftRadius="20dp"
android:bottomRightRadius="20dp"
android:topLeftRadius="20dp"
android:topRightRadius="20dp" />
</shape>