底部弹出的Popuwindow 用于更换头像

 

/****
 * 头像提示框
 */
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>

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值