PopWindows 底部显示与隐藏

来源:互联网 发布:牛扒和牛排区别知乎 编辑:程序博客网 时间:2024/05/22 04:55

參考链接:
* 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>
原创粉丝点击