自定义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 ...
随机推荐
- SCP和SFTP(转)
原文:http://www.cnblogs.com/wang_yb/p/3819441.html 不管SCP还是SFTP,都是SSH的功能之一.都是使用SSH协议来传输文件的. 不用说文件内容,就是登 ...
- Codeforces Round #368 (Div. 2) B. Bakery (模拟)
Bakery 题目链接: http://codeforces.com/contest/707/problem/B Description Masha wants to open her own bak ...
- postconf 命令常用参数
postfix的main.cf配置文件一般不直接编辑,而多使用postconf命令来配置‘ postconf -d:查看默认配置: postconf -n:查看当前配置(即当前生效的配置): post ...
- hdu1753I Hate It(线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=1754 单点更新,区间求最值 // File Name: hdu1754.cpp // Author: bo_jw ...
- Objc基础学习记录5
NSMutableString类继承的NSString类. NSMutableString是动态的字符串. 1.appendingString 方式: 向字符串尾部添加一个字符串. 2.appendi ...
- ASP.NET MVC- HtmlHelper的用法
在ASP.NET MVC框架中没有了自己的控件,页面显示完全就回到了写html代码的年代.还好在asp.net mvc框架中也有自带的HtmlHelper和UrlHelper两个帮助类.另外在MvcC ...
- Fragment实现底部选项卡切换效果
现在很多APP的样式都是底部选项卡做为首页的,实现这样的效果,我们一般有这样几种方式,第一,最屌丝的做法,我直接自定义选项卡视图,通过监听选项卡视图,逻辑控制内容页的切换,这样做的想法一般是反正这几个 ...
- UI:关于RGB与16进制颜色值的转换
IOS基本图形绘制 参考 取色对照表 参照 页面背景改为 #5CACEE 的颜色.有两个方法 方法一: 加两个宏 #define UIColorFromHexWithAlpha(hexValu ...
- 面试过程中javascript原型链与作用域的问题
现在校招也基本结束了,所以有时间把这段时间遇到的问题做个总结.在很多的笔试题目中,发现有很多对JS作用域方面的考察,所以查阅资料总结一下. 众所周知,js不像其他OOP语言那样,他是一种弱类型的语言, ...
- eclipse界面语言的切换方法
很久以前在我一个朋友的blog上看到过关于eclipse中英文语言界面切换的方法,觉得挺不错,后来自己也用过几次 现在想想,这个方法真的很不错,刚才又在自己机器上做了几次试验,发现eclipse事实上 ...