最近玩支付宝,有时候打开时,会从顶部掉下一个营销的广告窗口,效果图如下
分析:
1.从顶部往下掉,一个位移动画
背景半透明
首页构建广告界面
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#78666666"> <FrameLayout android:layout_gravity="center" android:layout_width="match_parent" android:layout_height="wrap_content"> <LinearLayout android:id="@+id/adArea" android:orientation="vertical" android:layout_gravity="center" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/closeIcon" android:src="@drawable/close" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageView android:id="@+id/adContent" android:src="@drawable/adcontent" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </FrameLayout> </FrameLayout>
用到的动画,顶部掉下来fade_in.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="1000" android:fromYDelta="-100%" android:toYDelta="0" /> <alpha android:startOffset="500" android:fromAlpha="0" android:toAlpha="1" android:duration="1000"/> </set>
退出时动画fade_out.xml
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android" android:fillAfter="true" android:fillBefore="false"> <translate android:duration="2000" android:fromYDelta="0" android:toYDelta="-100%" /> <scale android:startOffset="800" android:pivotX="0%" android:pivotY="0%" android:fromXScale="1" android:toXScale="0" android:fromYScale="1" android:duration="1000" android:toYScale="0"> </scale> </set>
启动Activity
package com.example.exportgradledemo; import android.app.Activity; import android.content.Context; import android.graphics.drawable.BitmapDrawable; import android.os.Bundle; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup.LayoutParams; import android.view.WindowManager; import android.widget.Button; import android.widget.PopupWindow; public class Main3Activity extends Activity { private android.widget.Button button; private PopupWindow popupWindow; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main3); this.button = (Button) findViewById(R.id.button); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showPopupWindow(); } }); } /** * 微信分享弹框 */ private void showPopupWindow() { if (popupWindow == null) { LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = layoutInflater.inflate(R.layout.popad_layout, null); popupWindow = new PopupWindow(view, LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT); } popupWindow.setFocusable(true); popupWindow.setOutsideTouchable(true); popupWindow.setAnimationStyle(R.style.AnimationPreview); // 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景 popupWindow.setBackgroundDrawable(new BitmapDrawable()); WindowManager windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); popupWindow.showAtLocation(findViewById(R.id.screen_content_layout), Gravity.BOTTOM, 0, 0); } }
相关推荐
自定义ProgressBar---跟随进度的 Popwindow 自定义ProgressBar---跟随进度的 Popwindow
使用popwindow简单实现的顶部筛选框,有简单的缩放效果,布局可自己调
Android -- PopWindow 的使用.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
仿微信加号popwindow和qqpopwindow下拉实现
自定义仿支付宝密码支付弹出框控件,注释详细,代码简单
使用popwindow实现仿uc界面的菜单
android PopWindow实例---一个简单的popWindow实例
仿微信加号和qq扫一扫的Popwindow菜单栏
android下popwindow的使用,详细注释
popwindow中加载Editext动态评论仿今日头条,解决各种问题
点击listview的某个item,在所点击的item的上部弹出popwindow, 手指弹起则消失,类似于qq消息的长按弹出的删除功能
收藏的Popwindow 弹出的小demo.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
android下拉列表样式筛选组件,仿美团popwindow实现,点击tab属性下拉显popwindow筛选条件
DropDownMenu,仿美团查询。已封装好,直接引入调用即可
2、底部弹出,从顶部向下弹出的效果,同时支持控制按钮执行动画,默认是旋转动画; 3、屏幕中间弹出 二、核心类PopWindow PopWindow采用Build模式,可以像AlertDialog一样方便的使用,通过PopWindowStyle控制弹窗...
自定义单选、多选对话框及popwindow窗口实例源码.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
主要介绍了Popwindow仿微信右上角下拉菜单实例代码的相关资料,非常不错具有参考借鉴价值,感兴趣的朋友一起看看吧
popwindow可以在你指定的地方弹出一个框来显示你想要的内容,貌似系统的spinner也是用的popwind来实现的(其中的一种方式),所以 想自定义一个控制更容易的下拉框用popwindow比较简单好实现
安卓开发-PopWindow.zip
对popwindow的一个简单封装,能够快捷使用popwindow