2017年8月26日,周结(二十三),PopupWindow的简单使用
来源:互联网 发布:90后听的经典网络歌曲 编辑:程序博客网 时间:2024/05/02 01:22
这周任务之中大部分还是调整或者是修改UI。
项目中很多东西还是不懂,所以功能方面我没有参与太多开发。
最大的收获就是学会了使用 Popupwindow
项目中需要实现一个从下往上弹出的提示框,所以先写了两个动画文件。
一个用来 show :
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="500" android:fromYDelta="100%p" android:toYDelta="0" /> <alpha android:duration="500" android:fromAlpha="0.0" android:toAlpha="1.0" /></set>一个用来 hide :
<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android"> <translate android:duration="500" android:fromYDelta="0" android:toYDelta="50%p" /> <alpha android:duration="500" android:fromAlpha="1.0" android:toAlpha="0.0" /></set>最后在 styles 文件中添加这样一个 Item
<style name="mypopwindow_anim_style"> <item name="android:windowEnterAnimation">@anim/popshow_anim</item> <!-- 指定显示的动画xml --> <item name="android:windowExitAnimation">@anim/pophidden_anim</item> <!-- 指定消失的动画xml --></style>接着写一下需要显示的弹窗的布局文件
<?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="wrap_content" android:background="@drawable/pop_lyt__bg" android:orientation="vertical"> <TextView android:textSize="15sp" android:textStyle="bold" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="25dp" android:gravity="center" android:text="No Location" android:textColor="@color/black" /> <TextView android:textColor="@color/black_alp50" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="15dp" android:gravity="center" android:text="In order to tell you how air quality is in your area, you need to grant AirPOP access to your phone's location in 'Settings'>'Privacy'>'Location Services'." /> <LinearLayout android:layout_marginTop="25dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="60dp" android:layout_marginRight="60dp" android:background="@drawable/btn_open_settting" android:gravity="center"> <TextView android:layout_marginTop="10dp" android:layout_marginBottom="10dp" android:id="@+id/pop_btn" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:text="Open Settings" android:textAllCaps="false" android:textColor="@color/white_alp70" android:textSize="20sp" /> </LinearLayout></LinearLayout>
效果如下
接着在 Java 代码中添加如下代码:
private PopupWindow popupWindow;
最终手机上的显示效果如下:View popwin = View.inflate(getContext(), R.layout.location_error_popwindow, null); int width = (int) ((getResources().getDisplayMetrics().widthPixels) * 0.9); int height = (int) ((getResources().getDisplayMetrics().heightPixels) * 0.35); popupWindow = new PopupWindow(popwin, width, height); TextView setting = (TextView) popwin.findViewById(R.id.pop_btn); setting.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); } }); popupWindow.setFocusable(true);// 取得焦点 //注意 要是点击外部空白处弹框消息 那么必须给弹框设置一个背景色 不然是不起作用的// popupWindow.setBackgroundDrawable(getResources().getDrawable(R.color.black)); //点击外部消失 popupWindow.setOutsideTouchable(true); //设置可以点击 popupWindow.setTouchable(true); //进入退出的动画 popupWindow.setAnimationStyle(R.style.mypopwindow_anim_style); popupWindow.showAtLocation(turboModelBuilding.lytLocationError, Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0);
阅读全文
0 0
- 2017年8月26日,周结(二十三),PopupWindow的简单使用
- 2017年6月9日,周结(十六),一些简单的算法题(二)
- 2009年3月19日 农历二月二十三
- 2017年3月3日,周结(二),几种UI控件的使用
- 2017年9月23日,周结(二十五),CountDownTimer的使用
- 2017年7月7日,周结(二十一),Activity的构成、Snackbar和TextInputLayout 的使用
- 2017年5月19日,周结(十三),数据结构与算法一些知识点
- popupwindow的简单使用
- PopupWindow的简单使用
- PopupWindow 的简单使用
- PopupWindow的简单使用
- popupWindow的简单使用
- Popupwindow 的简单使用
- PopupWindow的简单使用
- PopupWindow的简单使用
- PopupWindow的简单使用
- PopupWindow的简单使用
- popupWindow的简单使用
- PHP类
- 价格标
- vim基本命令的使用
- C++文件操作——查找某一类文件的三种方法
- 1.6 数组
- 2017年8月26日,周结(二十三),PopupWindow的简单使用
- zzuli 2184 河南多校联萌(5)(非二分)
- RabbitMQ消息队列之一:RabbitMQ的环境安装及配置
- FATAL ERROR: please install the following Perl modules before executing
- 正则表达式详解
- bootstrap table通过ajax获取后台数据展示在table
- python练习题
- 再起航,我的学习笔记之JavaScript设计模式12(适配器模式)
- 2017 8.25 阿里巴巴校招 在线笔试题