自定义PopupWindow弹出框(带有动画)
使用PopupWindow来实现弹出框,并且带有动画效果
首先自定义PopupWindow
public class LostPopupWindow extends PopupWindow {
public Lost lost;
public void onLost(Lost lost){
this.lost = lost;
}
private View conentView; public View getConentView() {
return conentView;
} public LostPopupWindow(final Activity context) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
conentView = inflater.inflate(R.layout.lost_pop_menu, null);
int h = context.getWindowManager().getDefaultDisplay().getHeight();
int w = context.getWindowManager().getDefaultDisplay().getWidth();
// 设置SelectPicPopupWindow的View
this.setContentView(conentView);
// 设置SelectPicPopupWindow弹出窗体的宽
this.setWidth(w / 2 + 50);
// 设置SelectPicPopupWindow弹出窗体的高
this.setHeight(LayoutParams.WRAP_CONTENT);
// 设置SelectPicPopupWindow弹出窗体可点击
this.setFocusable(true);
this.setOutsideTouchable(true);
// 刷新状态
this.update();
// 实例化一个ColorDrawable颜色为半透明
ColorDrawable dw = new ColorDrawable(0000000000);
// 点back键和其他地方使其消失,设置了这个才能触发OnDismisslistener ,设置其他控件变化等操作
this.setBackgroundDrawable(dw);
// mPopupWindow.setAnimationStyle(android.R.style.Animation_Dialog);
// 设置SelectPicPopupWindow弹出窗体动画效果
this.setAnimationStyle(R.style.AnimationPreview);
LinearLayout send = (LinearLayout) conentView
.findViewById(R.id.send);
LinearLayout mySend = (LinearLayout) conentView
.findViewById(R.id.my_send);
LinearLayout all = (LinearLayout) conentView.findViewById(R.id.all);
send.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View arg0) {
LostPopupWindow.this.dismiss();
lost.onLost(2);
}
}); mySend.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View v) {
LostPopupWindow.this.dismiss();
lost.onLost(1);
}
}); all.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LostPopupWindow.this.dismiss();
lost.onLost(0);
}
});
} /**
* 显示popupWindow
*
* @param parent
*/
public void showPopupWindow(View parent) {
if (!this.isShowing()) {
// 以下拉方式显示popupwindow
this.showAsDropDown(parent, parent.getLayoutParams().width / 2, 18);
} else {
this.dismiss();
}
} }
R.layout.lost_pop_menu文件
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:background="@drawable/black_menu_pop_bg"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"> <LinearLayout
android:id="@+id/send"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:orientation="horizontal"
android:scaleType="fitXY"> <ImageView
android:id="@+id/img5"
android:layout_width="20dp"
android:layout_height="20dp"
android:src="@drawable/icon_lost_add" /> <TextView
android:id="@+id/item_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="发布信息"
android:textColor="#e5e5e6"
android:textSize="18sp" />
</LinearLayout> <View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#616467" /> <LinearLayout
android:id="@+id/my_send"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:orientation="horizontal"> <ImageView
android:id="@+id/img6"
android:layout_width="20dp"
android:layout_height="20dp"
android:scaleType="fitXY"
android:src="@drawable/icon_lost_my" /> <TextView
android:id="@+id/item_content1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="我发布的信息"
android:textColor="#e5e5e6"
android:textSize="18sp" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#616467" /> <LinearLayout
android:id="@+id/all"
android:layout_width="match_parent"
android:layout_height="40dp"
android:gravity="center_vertical"
android:orientation="horizontal"> <ImageView
android:id="@+id/img7"
android:layout_width="20dp"
android:layout_height="20dp"
android:scaleType="fitXY"
android:src="@drawable/icon_all" /> <TextView
android:id="@+id/item_content2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="全部信息"
android:textColor="#e5e5e6"
android:textSize="18sp" />
</LinearLayout>
</LinearLayout>
动画R.style.AnimationPreview
<style name="AnimationPreview">
<item name="android:windowEnterAnimation">@anim/fade_in</item>
<item name="android:windowExitAnimation">@anim/fade_out</item>
</style> @anim/fade_in <?xml version="1.0" encoding="utf-8"?>
<!-- 左上角扩大-->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="0.001"
android:toXScale="1.0"
android:fromYScale="0.001"
android:toYScale="1.0"
android:pivotX="100%"
android:pivotY="10%"
android:duration="200" /> @anim/fade_out <!-- 左上角缩小 -->
<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:fromXScale="1.0"
android:toXScale="0.001"
android:fromYScale="1.0"
android:toYScale="0.001"
android:pivotX="100%"
android:pivotY="10%"
android:duration="200" />
接下来就是使用了
LostPopupWindow popWindow = new LostPopupWindow(ZiXunDetailActivity.this);
((ImageView)(popWindow.getConentView().findViewById(R.id.img5))).setImageResource(R.drawable.ckplico);
((ImageView)(popWindow.getConentView().findViewById(R.id.img6))).setImageResource(R.drawable.fbplico);
((ImageView)(popWindow.getConentView().findViewById(R.id.img7))).setImageResource(R.drawable.zfplico);
((TextView)(popWindow.getConentView().findViewById(R.id.item_content))).setText("查看评论");
((TextView)(popWindow.getConentView().findViewById(R.id.item_content1))).setText("发表评论");
((TextView)(popWindow.getConentView().findViewById(R.id.item_content2))).setText("转发文章");
popWindow.showPopupWindow(linMain);
popWindow.onLost(new Lost() {
@Override
public void onLost(int index) {
switch (index){
case 0: //转发文章
break;
case 1: //发表评论
lineFooter.setVisibility(View.VISIBLE);
break;
case 2://查看评论
Bundle bundle=new Bundle();
bundle.putString("id",mID);
startActivity(PingLunActivity.class, "热门评论", bundle);
break;
}
}
});
效果图
大家以后遇到类似的可以模仿使用
自定义PopupWindow弹出框(带有动画)的更多相关文章
- 练习PopupWindow弹出框之实现界面加载的时候显示弹出框到指定的view下面--两种延迟方法
今天在练习PopupWindow弹出框的时候,打算在界面加载的时候将弹出框展现出来并显示在指定的view下面. 初步方法是直接在OnResume方法里面直接执行showPopupWindows方法. ...
- UIPresentationController - iOS自定义模态弹出框
参考: https://developer.apple.com/library/archive/featuredarticles/ViewControllerPGforiPhoneOS/Definin ...
- 玩转Bootstrap(JS插件篇)-第1章 模态弹出框 :1-2 动画过渡
动画过渡(Transitions) 这一小节我们先来讲“动画过渡(Transitions)”这个插件的使用,源文件:transition.js Bootstrap框架默认给各个组件提供了基本动画的过渡 ...
- iOS自定义提示弹出框(类似UIAlertView)
菜鸟一枚,大神勿喷.自己在牛刀小试的时候,发现系统的UIAlertView有点不喜欢,然后就自己自定义了一个UIAlertView,基本上实现了系统的UIAlertView,可以根据项目的需求修改UI ...
- PopupWindow弹出框
使用PopupWindow实现一个悬浮框,悬浮在Activity之上,显示位置可以指定 首先创建pop_window.xml: <?xml version="1.0" enc ...
- 微信小程序之自定义底部弹出框动画
最近做小程序时,会经常用到各种弹框.直接做显示和隐藏虽然也能达到效果,但是体验性太差,也比较简单粗暴.想要美美地玩,添加点动画还是非常有必要的.下面做一个底部上滑的弹框. wxml <view ...
- swing自定义JDialog弹出框
第一次搞swing,自定义JDialog的例子较少,写下来备忘 ,对JDialog中的文本框进行了验证 package com.chauvet; import java.awt.Component; ...
- vue中点击屏幕其他区域关闭自定义div弹出框
直接上代码: mounted: function () { let that = this; $(document).on('click', function (e) { let dom = $('. ...
- 自定义ionic弹出框
<img width="64" height="64" src="img/timg.jpg" style="border-r ...
随机推荐
- 可变长参数列表误区与陷阱——va_arg不可接受的类型
可变长参数列表误区与陷阱--va_arg不可接受的类型 实现一个有可变长参数列表函数的时候,会使用到stdarg.h(这里不讨论varargs.h)中提供的宏. 例如,我们要实现一个简易的my_pri ...
- 主题敏感词PageRank
[主题敏感词PageRank] PageRank忽略了主题相关性,导致结果的相关性和主题性降低,对于不同的用户,甚至有很大的差别.例如,当搜索“苹果”时,一个数码爱好者可能是想要看 iphone 的信 ...
- windows 7 获取SYSTEM权限
当Adobe Reader 9.0卸载之后,你会发现原来的C:\Program Files\Adobe\Reader 9.0\Resource\CMap文件夹下的一些文件无法删除,提示你需要SYSTE ...
- CTE初识
微软从SQl2005起引入了CTE(Common Table Expression)以强化T-SQL.这是一个类似于非持久视图的好东西. 正常的SQL语句: select * from person. ...
- Uvalive 4865 Data Recovery 最大流
题意就是 给一个50 * 50的矩阵 然后给出每行每列元素的和 和一个初始矩阵 矩阵中有些是未知,有些是已知 然后我们求目标矩阵就是把能确定的元素的值求出来,实在不能确定的就置为-1 所有矩阵元素的值 ...
- DP练习(概率,树状,状压)
http://vjudge.net/contest/view.action?cid=51211#overview 花了好长时间了,终于把这个专题做了绝大部分了 A:HDU 3853 最简单的概率DP求 ...
- AFNetWorking3.0使用 自签名证书的https请求
前几日,项目组出于安全角度的考虑,要求项目中的请求使用https请求,因为是企业内部使用的app,因此使用了自签名的证书,而自签名的证书是不受信任的,所以我们就需要自己来做证书的验证,包括服务器验证客 ...
- C# 浅拷贝与深拷贝
浅拷贝:给对象拷贝一份新的对象引用地址:(只是给一个对象多起了个名字,所以,当改变拷贝的某个属性的时候,原对象的对应属性亦会改变).浅拷贝的定义—— 只对值类型(或string)类型分配新的内存地址: ...
- 无责任Windows Azure SDK .NET开发入门篇三[使用Azure AD 管理用户信息]
三.使用Azure AD管理用户信息 在上一章我们采用OpenID的方案和Azure AD交互进行身份验证,本章节我们继续了解如何在Azure AD中创建用户,列出用户信息,修改用户信息和删除用户信息 ...
- 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证--2.1使用Azure AD需要了解几个概念]
2.1使用Azure AD需要了解几个概念 l Azure AD目录 当你注册 Microsoft 云服务时,便会获得一个 Azure AD 目录.你可根据需要创建更多的目录.例如,可以将第一个目录保 ...