仿iOS底部弹出popUpWindow

上面为弹出来的效果
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的更多相关文章
- Android仿IOS底部弹出选择菜单ActionSheet
使用Dialog的实现方式,解决原ActionSheet使用Fragment实现而出现的部分手机取消按钮被遮盖的问题 java部分代码: import android.app.Dialog; impo ...
- Android仿ios底部弹出框效果
准备: public class ActionSheet { public interface OnActionSheetSelected { void onClick(int whichButton ...
- PopupWindowFromBottom 从底部弹出popupwindow
自定义PopupWindowFromBottom public class PopupWindowFromBottom extends PopupWindow { public PopupWindow ...
- 转 android 从底部弹出一个popuwindow,渐入渐出效果。我这里是用在购物车需要选择购买选项的操作。
最近要改客户端,需要实现一个从底部弹出的popuwindow,像我这种渣渣android技术,能整出popuwindow但是整不出动画,百度之,记录一下. 从下面这个地址转的 http://blog. ...
- 通用的popupwindow底部弹出框
前段时间做项目的时候,有几个底部弹出框,当时因为忙着赶进度所有就单独写了好几个popupwindow.后来就想着怎么实现一个通用的PopupWindow工具类 就是在要用到的时候创建该工具类的对象,并 ...
- h5页面ios键盘弹出收起后页面底部留白问题
<input placeholder="验证码" type="tel" v-model="verify" maxlength=&quo ...
- 仿QQ空间根据位置弹出PopupWindow显示更多操作效果
我们打开QQ空间的时候有个箭头按钮点击之后弹出PopupWindow会根据位置的变化显示在箭头的上方还是下方,比普通的PopupWindow弹在屏幕中间显示好看的多. 先看QQ空间效果图: ...
- PopupWindow底部弹出
说明:从屏幕底部弹出PopupWindow,有弹出隐藏动画效果.背景设置透明度. 效果图如下: 1.MainActivity.java 显示popwindow,宽高跟屏幕大小一样,设置一个透明度背 ...
- Android项目实战(十七):QQ空间实现(二)—— 分享功能 / 弹出PopupWindow
这是一张QQ空间说说详情的截图. 分析: .点击右上角三个点的图标,在界面底部弹出一个区域,这个区域有一些按钮提供给我们操作 .当该区域出现的时候,详情界面便灰了,也说成透明度变化了 .当任意选了一个 ...
随机推荐
- INSIDE COM 最后一章例子 TANGRAM 编译笔记
VS2013项目下载地址: http://pan.baidu.com/s/1gemrBrl 注册并运行: 使用管理员权限. 运行 REGISTER.BAT. 然后运行 TANGRAM.EXE 即可. ...
- java对象占多少内存
通常来说Hotspot jvm的对内存中的对象由以下几个部分组成 一个对象头,包含了一些整理工作所需信息 原始类型字段,不同类型大小各异(表1) 引用字段,占据4个字节(byte) 填充,在对象的末尾 ...
- expect实现交互式脚本
#!/usr/bin/expect -f ##告诉解释器用expect来解释 set timeout 6 ##设置超时时间 ] ## 这个是传递给脚本的第一个参数,并把参数赋值给user ] ## 这 ...
- Android 开发环境搭建以及编译
两种搭建编译环境的方式,一种方法是用户安装虚拟机,然后安装基础的Ubuntu12.04.2 系统,利用提供的工具和详细的使用步骤,搭建编译环境:另外一种方法是用户安装虚拟机,然后直接加载 “搭建好的U ...
- Leetcode: Range Sum Query - Mutable && Summary: Segment Tree
Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive ...
- qsort函数用法
qsort函数用法 qsort 功 能: 使用快速排序例程进行排序 用 法: void qsort(void *base, int nelem, int width, int (*fcmp)(co ...
- maven笔记-入门(helloWorld)
maven: pom.xml:文件 groupId,artifactId,Version定义了一个项目的基本坐标 groupId:定义了项目属于哪个组,往往与项目所在的组织和公司有关 artifact ...
- 从一个小项目看return 引用 重载运算符
#ifndef _ARRAY_H_ #define _ARRAY_H_ class Array { private: int mLength; int* mSpace; public: Array(i ...
- WPF中实现
计算类的封装 using System; using System.Collections.Generic; using System.Linq; using System.Text; namespa ...
- linux c
#include <stdio.h>#include <string.h>#include <strings.h> int main(){ char buf[ ...