自定义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 ...
随机推荐
- ArcObjects10.0引用控件报错
错误如下:ArcGIS version not specified. You must call RuntimeManager.Bind before creating any ArcGIS comp ...
- tomcat的 JNDI 配置
tomcat的conf/server.xml 配置 尽量用简单版 <Context path="/cas" docBase="D:\YC\zqV7\cas\WebR ...
- 8.3 LIS LCS LCIS(完结了==!)
感觉这个专题真不好捉,伤心了,慢慢啃吧,孩纸 地址http://acm.hust.edu.cn/vjudge/contest/view.action?cid=28195#overview 密码 ac ...
- UI进阶 FMDB
一.FMDB简介 1.FMDB简介 iOS中原生的SQLite API在进行数据存储的时候,需要使用C语言中的函数,操作比较繁琐.于是,就出现了一系列将SQLite API进行封装的库,例如FMDB. ...
- 关于JDBC 连接Access 数据库
************连接方式(一)Access_JDBC30.jar,此包由于是免费的,所有限制连接单次不超过50************************* Connection conn ...
- C++静态成员函数小结 [转]
类中的静态成员真是个让人爱恨交加的特性.我决定好好总结一下静态类成员的知识点,以便自己在以后面试中,在此类问题上不在被动. 静态类成员包括静态数据成员和静态函数成员两部分. 一 静态数据成员: 类体中 ...
- (剑指Offer)面试题35:第一个只出现一次的字符
题目: 在字符串中找出第一个只出现1次的字符,如输入“abaccdeff”,则输出b. 思路: 1.暴力遍历 从头开始扫描字符串中的每个字符,当访问某个字符时,取该字符与后面的每个字符相比较,如果没有 ...
- 深入Delphi -- Windows 消息机制
http://www.txsz.net/xs/delphi/3/Windows%20%E6%B6%88%E6%81%AF%E6%9C%BA%E5%88%B6.htm Windows 消息机制 by m ...
- Windows常用性能计数器总结
基础监控: Processor:% Processor Time CPU当前利用率,百分比 Memory:Available MBytes 当前可用内存,兆字节(虚拟内存不需要监控,只有当物理内存不够 ...
- FluentData官方文档翻译
开始 要求 .NET 4.0. 支持的数据库 MS SQL Server using the native .NET driver. MS SQL Azure using the native .NE ...