上面为弹出来的效果

popUpWindow布局:

<?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:padding="5dp"
android:orientation="vertical"> <LinearLayout
android:padding="2dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:background="@drawable/popwindow_bg"//使用shape画出圆角矩形,边框为为灰色,背景为白色。颜色不要再线性布局中设置,也会掩盖圆角矩形。
android:orientation="vertical"> <TextView
android:id="@+id/takePhoto"
style="@style/bottom_pop_textview"//宽不能设为match_parent,否则外层的圆角矩形会被遮盖。
android:text="拍照" />
<TextView
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
/>
<TextView
android:id="@+id/openPhotos"
style="@style/bottom_pop_textview"
android:layout_marginTop="1dp"
android:text="打开相册"
/> </LinearLayout>
<LinearLayout
android:padding="2dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:layout_marginTop="10dp"
android:background="@drawable/popwindow_bg"//使用shape画出圆角矩形,边框为为灰色,背景为白色。
android:orientation="vertical">
<TextView
android:id="@+id/cancel"
style="@style/bottom_pop_textview"
android:text="取消"
/>
</LinearLayout> </LinearLayout>

shape画出圆角矩形 代码:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
>
<stroke android:width="1dip" android:color="#ffbbbbbb"/>
<corners android:topLeftRadius="15dip"
android:topRightRadius="15dip"
android:bottomLeftRadius="15dip"
android:bottomRightRadius="15dip" />
<solid android:color="@android:color/white"/>
</shape>

从底部弹出popupwindow:

/**
* 从底部弹出popupwindow
*/
private void showBottomPop(View parent) {
final View popView = View.inflate(getActivity(), R.layout.bottom_pop_layout, null);
showAnimation(popView);//开启动画
PopupWindow mPopWindow = new PopupWindow(popView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
clickPopItem(popView, mPopWindow);//条目的点击
mPopWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
mPopWindow.showAtLocation(parent,
Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
mPopWindow.setOutsideTouchable(true);
mPopWindow.setFocusable(true);
mPopWindow.update();
// 设置背景颜色变暗
WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
lp.alpha = 0.7f;
getActivity().getWindow().setAttributes(lp);
mPopWindow.setOnDismissListener(new PopupWindow.OnDismissListener() { @Override
public void onDismiss() {
WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
lp.alpha = 1f;
getActivity().getWindow().setAttributes(lp);
}
});
}

弹出的动画:

/**
* 给popupwindow添加动画
*
* @param popView
*/
private void showAnimation(View popView) {
AnimationSet animationSet = new AnimationSet(false);
AlphaAnimation alphaAnimation = new AlphaAnimation(0f, 1.0f);
alphaAnimation.setDuration(300);
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
Animation.RELATIVE_TO_SELF, 1f, Animation.RELATIVE_TO_SELF, 0f
);
translateAnimation.setDuration(300);
animationSet.addAnimation(alphaAnimation);
animationSet.addAnimation(translateAnimation);
popView.startAnimation(animationSet);
}

仿iOS底部弹出popUpWindow的更多相关文章

  1. Android仿IOS底部弹出选择菜单ActionSheet

    使用Dialog的实现方式,解决原ActionSheet使用Fragment实现而出现的部分手机取消按钮被遮盖的问题 java部分代码: import android.app.Dialog; impo ...

  2. Android仿ios底部弹出框效果

    准备: public class ActionSheet { public interface OnActionSheetSelected { void onClick(int whichButton ...

  3. PopupWindowFromBottom 从底部弹出popupwindow

    自定义PopupWindowFromBottom public class PopupWindowFromBottom extends PopupWindow { public PopupWindow ...

  4. 转 android 从底部弹出一个popuwindow,渐入渐出效果。我这里是用在购物车需要选择购买选项的操作。

    最近要改客户端,需要实现一个从底部弹出的popuwindow,像我这种渣渣android技术,能整出popuwindow但是整不出动画,百度之,记录一下. 从下面这个地址转的 http://blog. ...

  5. 通用的popupwindow底部弹出框

    前段时间做项目的时候,有几个底部弹出框,当时因为忙着赶进度所有就单独写了好几个popupwindow.后来就想着怎么实现一个通用的PopupWindow工具类 就是在要用到的时候创建该工具类的对象,并 ...

  6. h5页面ios键盘弹出收起后页面底部留白问题

    <input placeholder="验证码" type="tel" v-model="verify" maxlength=&quo ...

  7. 仿QQ空间根据位置弹出PopupWindow显示更多操作效果

    我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图:       ...

  8. PopupWindow底部弹出

    说明:从屏幕底部弹出PopupWindow,有弹出隐藏动画效果.背景设置透明度. 效果图如下: 1.MainActivity.java   显示popwindow,宽高跟屏幕大小一样,设置一个透明度背 ...

  9. Android项目实战(十七):QQ空间实现(二)—— 分享功能 / 弹出PopupWindow

    这是一张QQ空间说说详情的截图. 分析: .点击右上角三个点的图标,在界面底部弹出一个区域,这个区域有一些按钮提供给我们操作 .当该区域出现的时候,详情界面便灰了,也说成透明度变化了 .当任意选了一个 ...

随机推荐

  1. 用仿ActionScript的语法来编写html5——终篇,LegendForHtml5Programming1.0开源库件

    一,LegendForHtml5Programming1.0库件是什么?它是一个javascript库,它模仿了ActionScript的语法,用于html5的开发,目前实现的功能相对较少,还不能称之 ...

  2. swiper有时候不能自动滚动的问题

    <script type="text/javascript"> $(function(){ var swiper = new Swiper('.swiper-conta ...

  3. Java基础之创建窗口——向窗口中添加菜单(Sketcher)

    控制台程序. JMenuBar对象表示放在窗口顶部的菜单栏.可以为JMenuBar对象添加JMenu或JMenuItem对象,它们都显示在菜单栏上.JMenu对象是带有标签的菜单,单击就可以显示一列菜 ...

  4. Servlet 3特性:异步Servlet

    解异步Servlet之前,让我们试着理解为什么需要它.假设我们有一个Servlet需要很多的时间来处理,类似下面的内容: LongRunningServlet.java package com.jou ...

  5. HTML语言的一些元素(五)

    一.table表格语法与结构 <table> <tr> <td> </td> <td> </td> <td> < ...

  6. struts 2.0部署

    环境:linux centos 64位. 1)下载JDK6.0,具体文件名是:jdk-6u45-linux-x64.bin 安装:chmod 755 jdk*.bin ./jdk....bin 设置环 ...

  7. (转)@SuppressWarnings的使用、作用、用法

    在java编译过程中会出现很多警告,有很多是安全的,但是每次编译有很多警告影响我们对error的过滤和修改,我们可以在代码中加上 @SuppressWarnings(“XXXX”) 来解决 例如:@S ...

  8. 转:windows 7系统安装与配置Tomcat服务器环境

    工具/原料 jdk-7u45-windows-x64(我的系统是64位系统,32位的请选x86下载) apache-tomcat-8.0.0-RC5-windows-x64 方法/步骤   下载说明, ...

  9. JQuery下CheckBox全选全不选反选

    <script src="JS/jquery-1.7.1.js"></script> <script type="text/javascri ...

  10. codevs 1204 寻找子串位置

    http://codevs.cn/problem/1204/ 1204 寻找子串位置  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 青铜 Bronze 题解  查看运行结果 ...