- ubuntu12.04环境下使用kvm ioctl接口实现最简单的虚拟机
- Ubuntu 通过无线网络安装Ubuntu Server启动系统后连接无线网络的方法
- 在Ubuntu上搭建网桥的方法
- ubuntu 虚拟机上网方式及相关配置详解
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界.
这篇CFSDN的博客文章Android Animation实战之屏幕底部弹出PopupWindow由作者收集整理,如果你对这篇文章有兴趣,记得点赞哟.
android动画的一个实战内容,从屏幕底部滑动弹出popupwindow。 相信这种效果大家在很多app上都遇到过,比如需要拍照或者从sd卡选择图片,再比如需要分享某些东西时,大多会采用这么一种效果:
那这种效果如何实现呢? 我们仿写一个这种效果的实例吧:
1)我们首先定义一下,弹出窗口的页面布局组件:take_photo_pop.xml 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<relativelayout xmlns:android=
"http://schemas.android.com/apk/res/android"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:gravity=
"center_horizontal"
android:orientation=
"vertical"
>
<linearlayout
android:id=
"@+id/pop_layout"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:background=
"#ffffff"
android:layout_alignparentbottom=
"true"
android:gravity=
"center_horizontal"
android:orientation=
"vertical"
>
<textview
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:clickable=
"false"
android:gravity=
"center"
android:text=
"修改头像"
android:textcolor=
"#8a8a8a"
android:textsize=
"15sp"
/>
<view
android:layout_width=
"fill_parent"
android:layout_height=
"0.1dp"
android:layout_marginleft=
"10dp"
android:layout_marginright=
"10dp"
android:background=
"#00c7c0"
/>
<button
android:id=
"@+id/btn_take_photo"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:text=
"拍照"
android:textcolor=
"#0e61aa"
android:textsize=
"18sp"
/>
<button
android:id=
"@+id/btn_pick_photo"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:text=
"从相册选择"
android:textcolor=
"#0e61aa"
android:textsize=
"18sp"
/>
<button
android:id=
"@+id/btn_cancel"
android:layout_width=
"fill_parent"
android:layout_height=
"wrap_content"
android:layout_marginbottom=
"15dip"
android:layout_margintop=
"15dip"
android:text=
"取消"
android:textcolor=
"#0e61aa"
android:textsize=
"18sp"
android:textstyle=
"bold"
/>
</linearlayout>
</relativelayout>
|
2)现在定义动画,要知道该popupwindow出现时是从页面底部向上滑动,消失时是从上向下滑动消失,,所以我们需要定义两个动画文件: 退出动画pop_exit_anim.xml 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<set xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:duration=
"200"
android:fromydelta=
"0"
android:toydelta=
"50%p"
/>
<alpha
android:duration=
"200"
android:fromalpha=
"1.0"
android:toalpha=
"0.0"
/>
</set>
显示动画pop_enter_anim.xml
<?xml version=
"1.0"
encoding=
"utf-8"
?>
<set xmlns:android=
"http://schemas.android.com/apk/res/android"
>
<translate
android:duration=
"200"
android:fromydelta=
"100%p"
android:toydelta=
"0"
/>
<alpha
android:duration=
"200"
android:fromalpha=
"0.0"
android:toalpha=
"1.0"
/>
</set>
|
关于这两个动画,此处不再多做解析,读过我之前博文的都应该知道啦,很简单的,若是看不懂?请点击此文上方的链接学习之。 3)自定义弹出框popupwindow:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import
android.content.context;
import
android.graphics.drawable.colordrawable;
import
android.view.layoutinflater;
import
android.view.motionevent;
import
android.view.view;
import
android.widget.button;
import
android.widget.popupwindow;
import
android.widget.relativelayout;
public
class
takephotopopwin
extends
popupwindow {
private
context mcontext;
private
view view;
private
button btn_take_photo, btn_pick_photo, btn_cancel;
public
takephotopopwin(context mcontext, view.onclicklistener itemsonclick) {
this
.view = layoutinflater.from(mcontext).inflate(r.layout.take_photo_pop,
null
);
btn_take_photo = (button) view.findviewbyid(r.id.btn_take_photo);
btn_pick_photo = (button) view.findviewbyid(r.id.btn_pick_photo);
btn_cancel = (button) view.findviewbyid(r.id.btn_cancel);
// 取消按钮
btn_cancel.setonclicklistener(
new
view.onclicklistener() {
public
void
onclick(view v) {
// 销毁弹出框
dismiss();
}
});
// 设置按钮监听
btn_pick_photo.setonclicklistener(itemsonclick);
btn_take_photo.setonclicklistener(itemsonclick);
// 设置外部可点击
this
.setoutsidetouchable(
true
);
// mmenuview添加ontouchlistener监听判断获取触屏位置如果在选择框外面则销毁弹出框
this
.view.setontouchlistener(
new
view.ontouchlistener() {
public
boolean
ontouch(view v, motionevent event) {
int
height = view.findviewbyid(r.id.pop_layout).gettop();
int
y = (
int
) event.gety();
if
(event.getaction() == motionevent.action_up) {
if
(y < height) {
dismiss();
}
}
return
true
;
}
});
/* 设置弹出窗口特征 */
// 设置视图
this
.setcontentview(
this
.view);
// 设置弹出窗体的宽和高
this
.setheight(relativelayout.layoutparams.match_parent);
this
.setwidth(relativelayout.layoutparams.match_parent);
// 设置弹出窗体可点击
this
.setfocusable(
true
);
// 实例化一个colordrawable颜色为半透明
colordrawable dw =
new
colordrawable(
0xb0000000
);
// 设置弹出窗体的背景
this
.setbackgrounddrawable(dw);
// 设置弹出窗体显示时的动画,从底部向上弹出
this
.setanimationstyle(r.style.take_photo_anim);
}
}
|
定义要弹出的组件takephotopopwin,它继承自popupwindow,具体如何实现的,我备注信息很详细了。 有一个地方要提醒的是,就是最后要设置弹出窗体的显示动画,this.setanimationstyle(r.style.take_photo_anim); 这是必不可少的,只有加上了它,才能应用动画效果! 看下take_photo_anim style的定义:
1
2
3
4
|
<style name=
"take_photo_anim"
parent=
"android:animation"
>
<item name=
"android:windowenteranimation"
>
@anim
/pop_enter_anim</item>
<item name=
"android:windowexitanimation"
>
@anim
/pop_exit_anim</item>
</style>
|
就这么几步,一个可以从屏幕底部滑动弹出的组件 。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public
void
showpopformbottom(view view) {
takephotopopwin takephotopopwin =
new
takephotopopwin(
this
, onclicklistener);
//showatlocation(view parent, int gravity, int x, int y)
takephotopopwin.showatlocation(findviewbyid(r.id.main_view), gravity.center,
0
,
0
);
}
private
view.onclicklistener onclicklistener =
new
view.onclicklistener() {
@override
public
void
onclick(view v) {
switch
(v.getid()) {
case
r.id.btn_take_photo:
system.out.println(
"btn_take_photo"
);
break
;
case
r.id.btn_pick_photo:
system.out.println(
"btn_pick_photo"
);
break
;
}
}
};
|
这下子,效果就和我一开始传的图一致啦!有木有学会了呢!?
拓展: 玩过app的大家都知道,在你进入新页面或者注册登录啥的时候,都会弹出一个等待的框框,表示网络请求中,你需要耐心等待下,比如微信的等待请求框效果如下:
这里面其中也有个地方用到了动画,那就是不停旋转的那个小图标,它其实用的就是旋转动画! 关于如何实现这么样一个旋转等待框,我以前写过一篇介绍的文章,可查看: 《android自定义progressdialog进度等待框》 。
最后此篇关于Android Animation实战之屏幕底部弹出PopupWindow的文章就讲到这里了,如果你想了解更多关于Android Animation实战之屏幕底部弹出PopupWindow的内容请搜索CFSDN的文章或继续浏览相关文章,希望大家以后支持我的博客! 。
我想使用 linux 终端在 .txt 文档中找到字符串 animal-0**。 ** 是从 60 到 69 的数字。我想我必须在命令中使用 grep 和正则表达式:grep -E 'animal-0
在他的C# 深入一书中,Jon Skeet 试图回答以下问题: Why can't I convert List to List? 为了解释它,他从一个代码片段开始,其中包括以下两行: Animal[
我对此有点困惑,所以希望能提供一些说明。 public void addAll(List animals) 对比 public void addAll(List animals) 最佳答案 区别在于
我遇到的情况是,我有许多CALayer以“基于回合”的方式进行动画处理。我为每个CALayer上的位置设置了动画,但是它们具有完全相同的持续时间。一旦所有这些CALayer动画完成,就会启动一个新的“
我为正在拔出的刀和空闲状态设置了动画,但是无论我做什么,它们都不会在游戏中设置动画。相反,它卡住在第一帧上。这是动画窗口运行时的样子: 动画: 在检查器中: 最佳答案 我遇到了类似的问题,它归结于动画
我的单个 HTML 文件中嵌入了 2 个页面。所以它所做的是最初它显示 PAGE1,然后如果我从右向左或从左向右滑动 PAGE2 应该显示。我的问题是如何根据我的滑动更改页面动画?比如当我从右向左滑动
我想做一个动画标题。 我创建了一个 FlatList 的动画组件, 用过 onScroll函数来更新动画值。 使用绝对位置放置一个 View (Animated.View) 作为动画 FlatList
我想制作一个打开的窗帘的动画。我有两张图像:一张用于窗帘的左侧,一张用于窗帘的右侧(以红色表示)。我想用核心动画顺利地将它们滑走。我应该寻找什么类型的动画?如何实现逼真的滑动风格? 问候, 斯特凡 a
我有一个简单的旋转动画,可以让一个对象绕其轴旋转。目前它旋转得太快了,我想减慢速度,我试过增加样本??但我对动画了解不多,所以我可能过得很好。如何放慢动画速度?它只有两个键。 最佳答案 首先,通过双击
我似乎无法在上类时获得 angularjs ng-animate,而且在野外似乎也没有任何示例。以演示 fiddle 为例: http://jsfiddle.net/yfajy/ 向 CSS 添加如下
使用以下代码段:http://jsfiddle.net/sylouuu/V7a3Y/2/ 我想在动画的#log 中显示从 0% 到 100% 的进度百分比,100% 很容易通过回调... 有可能这样做
我正在 HTML 中使用 SVG 来使用折线工具定义特定的形状。我希望通过按一下按钮并在几秒钟内将特定形状的外观动画化为不同的形状。 我一直在考虑使用动画工具来更改折线点属性,但到目前为止一直无法找到
您好,在 Firefox(相当糟糕)和 Chrome 之间获得可变性能和效果(还可以)有时这不会执行第一个动画,有时会卡住。 我的结构正确吗? $notification.animate({
我在 iOS 编程时遇到了一个问题:当我尝试为我的 tableView 制作自定义编辑按钮时,我无法将其设置为动画。下面是我如何初始化 tableview: - (void)viewWillAppea
自 beta 5 以来,我注意到在 OS X 10.10 下隐式动画有一些奇怪的行为。调用动画代理有时会导致应用程序崩溃。我设置了一个非常简单的自定义 View 。这是完整的代码: import Co
我正在开发一个可折叠组件,您可以单击它来向上/向下滚动以显示/隐藏详细信息。组件如下: // component.ts import {Component, Directive, Input} fro
我正在努力了解 web animations standard和他们的 polyfill ,正如我所见,它在 Angular 动画库中运行良好(您将动画结束值设置为“*”,这将变为 div 大小的 1
我想创建一个动画闪屏,但出现此错误: Android.Content.Res.Resources+NotFoundException: File res/drawable/splash_screen.
我正在尝试对我的应用程序应用慢动作效果,就像按 Shift 时如何减慢 Mac OS 的大多数图形效果一样。 我的应用程序使用 CoreAnimation,所以我认为它应该没什么大不了的:set sp
我想以编程方式同时不在XML文件中显示两个动画,它应该 ROTATE和TRANSLATE 我怎样才能做到这一点? 请以某种方式建议我?????? 这是ma代码:> ImageView snowImg1
我是一名优秀的程序员,十分优秀!