PopWindows 底部显示与隐藏

參考链接:
* http://blog.csdn.net/mannver/article/details/51399151
* http://104zz.iteye.com/blog/1685389

要实现PopWindow底部的显隐

这里写图片描述

定义PopWindow要展示的布局

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/gray">

    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:layout_marginBottom="2dp"
        android:gravity="center"
        android:text="选择图片"
        android:textStyle="bold"
        android:background="@color/white"/>
    <TextView
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="拍照片"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginBottom="2dp"
        android:background="@color/white"/>

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="做标记"
        android:textStyle="bold"
        android:gravity="center"
        android:layout_marginBottom="20dp"
        android:background="@color/white" />

    <TextView
        android:id="@+id/textView1"
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:text="取消"
        android:textStyle="bold"
        android:gravity="center"
        android:background="@color/white" />
</LinearLayout>

PopWindow逻辑上的实现

    private void initPop() {
        View view = LayoutInflater.from(this).inflate(R.layout.pop, null, false);
        PopupWindow popupWindow = new PopupWindow(view,
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        //设置SelectPicPopupWindow弹出窗体可点击
        popupWindow.setFocusable(true);
        //设置SelectPicPopupWindow弹出窗体动画效果
        //进入退出的动画
        popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style);
        //实例化一个ColorDrawable颜色为半透明
        ColorDrawable dw = new ColorDrawable(0xb0000000);
        //点击外部消失
        popupWindow.setOutsideTouchable(false);
        //设置可以点击
        popupWindow.setTouchable(true);
        //设置SelectPicPopupWindow弹出窗体的背景
//        popupWindow.setBackgroundDrawable(dw);
        //注意  要是点击外部空白处弹框消息  那么必须给弹框设置一个背景色  不然是不起作用的
        popupWindow.setBackgroundDrawable(new BitmapDrawable());、
        // 注:此处的R.id.main则是最外层布局View
        popupWindow.showAtLocation(MainActivity.this.findViewById(R.id.main), Gravity.BOTTOM|Gravity.CENTER_HORIZONTAL, 0, 0);
    }

动画(另附)

上述代码中的 R.style.mypopwindow_anim_style

<style name="mypopwindow_anim_style">
        <item name="android:windowEnterAnimation">@anim/popshow_anim</item>
        <!-- 指定显示的动画xml -->
        <item name="android:windowExitAnimation">@anim/pophidden_anim</item>
        <!-- 指定消失的动画xml -->
</style>

@anim/popshow_anima

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
    <translate
        android:duration="500"
        android:fromYDelta="100%p"
        android:toYDelta="0" />

    <alpha
        android:duration="500"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />
</set>

紫色圆形背景

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.co/apk/res/android" android:shape="oval"
   android:innerRadius="20dp"  >
    <size android:height="40dp" android:width="40dp" ></size>
    <solid android:color="@color/purple"></solid>
</shape>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值