自定义popwindow,从底部弹出和消失动画
2016-07-09 22:10
471 查看
1.使用方法
2.自定义popwindow
3.在style中设置动画样式
4.popwindow布局custom_popwindow.xml
5.anim 动画样式
popWindow = new CustomPopWindow(this, new View.OnClickListener() { @Override public void onClick(View v) { } } }); popWindow.showAtLocation(this.findViewById(R.id.etActivityEditFeedBack),Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); //设置layout在PopupWindow中显示的位置
2.自定义popwindow
public class CustomPopWindow extends PopupWindow implements View.OnClickListener { private TextView OK; private TextView GiveUp; private TextView Cancel; private View mMenuView; public CustomPopWindow(Activity context, View.OnClickListener itemsOnClick) { super(context); LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); mMenuView = inflater.inflate(R.layout.custom_popwindow, null); mMenuView.setOnClickListener(this); OK = (TextView) mMenuView.findViewById(R.id.tvPopwindowOK); GiveUp = (TextView) mMenuView.findViewById(R.id.tvPopwindowGiveUp); Cancel = (TextView) mMenuView.findViewById(R.id.tvPopwindowCancel); Cancel.setOnClickListener(this); OK.setOnClickListener(itemsOnClick); GiveUp.setOnClickListener(itemsOnClick); //设置SelectPicPopupWindow的View setContentView(mMenuView); //设置SelectPicPopupWindow弹出窗体的宽 setWidth(LinearLayout.LayoutParams.MATCH_PARENT); // //设置SelectPicPopupWindow弹出窗体的高 setHeight(LinearLayout.LayoutParams.MATCH_PARENT); ColorDrawable dw = new ColorDrawable(0x00000000); setBackgroundDrawable(dw); setFocusable(true); setAnimationStyle(R.style.popwindow_anim_style); } @Override public void onClick(View v) { dismiss(); } }
3.在style中设置动画样式
<!-- Popwindow样式 --> <style name="popwindow_anim_style"> <item name="android:windowEnterAnimation">@anim/popwindow_show_anim</item> <item name="android:windowExitAnimation">@anim/popwindow_hidden_anim</item> </style>
4.popwindow布局custom_popwindow.xml
<?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="match_parent" android:background="#90000000" android:gravity="bottom|center_horizontal" android:orientation="vertical"> <TextView android:id="@+id/tvPopwindowOK" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/background_titlebar" android:gravity="center" android:padding="@dimen/padding_10" android:text="完成编辑" android:textSize="@dimen/text_size_18" /> <TextView android:id="@+id/tvPopwindowGiveUp" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@drawable/background_titlebar" android:gravity="center" android:padding="@dimen/padding_10" android:text="放弃编辑" android:textColor="@color/color_red" android:textSize="@dimen/text_size_18" /> <TextView android:id="@+id/tvPopwindowCancel" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="@dimen/padding_10" android:layout_marginTop="@dimen/padding_10" android:background="@drawable/background_titlebar" android:gravity="center" android:padding="10dp" android:text="取消" android:textSize="@dimen/text_size_18" /> </LinearLayout>
5.anim 动画样式
popwindow_show_anim.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/ 4000 android"> <translate android:duration="1000" android:fromYDelta="100%p" android:toYDelta="0" /> </set> popwindow_hidden_anim.xml <?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="1000" android:fromYDelta="0" android:toYDelta="100%p" /> </set>
相关文章推荐
- 1、linux软件包管理
- zabbix监控nginx
- OpenLayers2 源码解读 事件Event、Events
- OpenGL(四)光照材质
- OpenLayers2 源码解析(3)Map
- Linux is not Matrix——感受黑科技吧,网页安装mysql cluster
- nginx lvs keepalived搭建集群
- linux下查看最消耗CPU、内存的进程
- perl 自动登陆网站发短信
- perl 自动登陆网站发短信
- perl 自动登陆网站发短信
- Linux Runtime Memory Measurement
- 3 LNMP
- linux下进行c/c++开发
- Linux内核的namespace机制分析
- cnetos7更改网卡类型
- freopen ()函数
- "围观"设计模式(31)--行为型设计模式总结(模板、观察者、策略、状态、责任链、命令、访问者、中介者、备忘录、解释器)
- apache 日志中记录代理IP以及真实客户端IP
- 华为机试---社交网站好友推荐