- 浏览: 41193 次
- 性别:
- 来自: 济南
最新评论
-
kensunhu:
正是我想要的。典型的app ui布局。谢谢!
android UI - 仿威信tab样式 -
007007jing:
bing_zz 写道兄弟加油!谢谢
android2.3 api demo 学习系列(7)--App/Activity/Hello World -
bing_zz:
兄弟加油!
android2.3 api demo 学习系列(7)--App/Activity/Hello World
1、首先学习sdk中关于Animation的说明。andorid的动画主要分为下面三种
- Property Animation
版本要求: Android 3.0 (API level 11), property animation支持任何对象的动画效果,也是android推荐的模式。 可以很好的扩展。(因为本次demo版本为2.3 在这里不在研究,留在以后研究)
- View Animation
View Animation 只能在Views使用. 优点是实现简单.缺点也很明显:首先只支持view,其次是他只是改变view的动画效果,并没有实际改变view,例如让一个按钮在屏幕上移动,动画效果是正确实现,但是按钮的点击位置并没有改变,需要自己另外实现。
View Animation提供了Tween和frame两种实现方式。
接下来学习Tween Animation:
动画的定义可以使用xml配置文件或者代码实现。xml配置文件定义相对于代码实现具有可读性、重用行、方便维护等特性,配置文件放置在工程的res/anim/文件内,xml配置文件必须包含下面其中一个元素:<alpha>
, <scale>
,<translate>
, <rotate>
或者 <set>
,嵌套set。例如下面的一个示例拉伸旋转view
<set android:shareInterpolator="false"> <scale android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fromXScale="1.0" android:toXScale="1.4" android:fromYScale="1.0" android:toYScale="0.6" android:pivotX="50%" android:pivotY="50%" android:fillAfter="false" android:duration="700" /> <set android:interpolator="@android:anim/decelerate_interpolator"> <scale android:fromXScale="1.4" android:toXScale="0.0" android:fromYScale="0.6" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" android:fillBefore="false" /> <rotate android:fromDegrees="0" android:toDegrees="-45" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:startOffset="700" android:duration="400" /> </set> </set>
保存xml文件后在代码中调用
ImageView spaceshipImage = (ImageView) findViewById(R.id.spaceshipImage); Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(this, R.anim.xml配置文件); spaceshipImage.startAnimation(hyperspaceJumpAnimation);
接下来看看每一个的属性
set:
android:interpolator:可以使用平台提供的属性 如下图所示
如果你觉得平台定义的不符合需求,可以更改他们(定义的时候名字强制使用小写)
各个Interpolator的属性如下
<accelerateDecelerateInterpolator>
<accelerateInterpolator>
attributes:
android:factor
<anticipateInterpolator>
attributes:
android:tension
<anticipateOvershootInterpolator>
attributes:
android:tension
android:extraTension
<bounceInterpolator>
No attributes
<cycleInterpolator>
attributes:
android:cycles
<decelerateInterpolator>
attributes:
android:factor
<linearInterpolator>
No attributes.
<overshootInterpolator>
attributes:
android:tension
修改时例如下面的xml定义
<?xml version="1.0" encoding="utf-8"?> <overshootInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:tension="7.0" /> xml文件保存在res/anim文件夹内
同事别的动画配置文件可以引用interpolator 例如
<scale xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@anim/预先定义的interpolator" android:fromXScale="1.0" android:toXScale="3.0" android:fromYScale="1.0" android:toYScale="3.0" android:pivotX="50%" android:pivotY="50%" android:duration="700" />
set的另外一个属性 android:shareInterpolator:true向所有的子元素共享interpolator
<alpha>
AlphaAnimation
.
attributes:
android:fromAlpha
android:toAlpha
<scale>
pivotX
and pivotY
. For example, if these values are 0, 0 (top-left corner), all growth will be down and to the right. Represents a ScaleAnimation
.
attributes:
android:fromXScale
android:toXScale
android:fromYScale
android:toYScale
android:pivotX
android:pivotY
<translate>
TranslateAnimation
.
attributes:
android:fromXDelta
"5"
), in percentage relative to the element width (such as "5%"
), or in percentage relative to the parent width (such as "5%p"
).android:toXDelta
"5"
), in percentage relative to the element width (such as "5%"
), or in percentage relative to the parent width (such as "5%p"
).android:fromYDelta
"5"
), in percentage relative to the element height (such as "5%"
), or in percentage relative to the parent height (such as "5%p"
).android:toYDelta
"5"
), in percentage relative to the element height (such as "5%"
), or in percentage relative to the parent height (such as "5%p"
).<rotate>
RotateAnimation
.
attributes:
android:fromDegrees
android:toDegrees
android:pivotX
"5"
), in percentage relative to the object's left edge (such as "5%"
), or in percentage relative to the parent container's left edge (such as "5%p"
).android:pivotY
"5"
), in percentage relative to the object's top edge (such as "5%"
), or in percentage relative to the parent container's top edge (such as "5%p"
).
上述<alpha>
, <scale>
, <translate>
, <rotate>同样拥有下图中得属性
介绍完了tween animation 接下来看看 frame animation的内容
frame animation主要是定义显示一系列图片的动画,xml配置文件保存在res/drawable/ xml的语法如下:
<?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot=["true" | "false"] > <item android:drawable="@[package:]drawable/图片资源引用" android:duration="integer持续时间" /> </animation-list>
在按照语法定义完后 xml可以保存在 res/anim or drawable文件夹下面
调用代码如下 为什么在这个方法里面调用 请看注释不多解释
@Override public void onWindowFocusChanged(boolean hasFocus) { // TODO Auto-generated method stub super.onWindowFocusChanged(hasFocus); //图片背景置换 frame animation //此段代码为什么放在 onWindowFocusChanged //因为当我们在onCreate中调用AnimationDrawable的start方法时,窗口Window对象还没有完全初始化, //AnimationDrawable不能完全追加到窗口Window对象中,那么该怎么办呢?我们需要把这段代码放在onWindowFocusChanged方法中, //当Activity展示给用户时,onWindowFocusChanged方法就会被调用,我们正是在这个时候实现我们的动画效果。 //当然,onWindowFocusChanged是在onCreate之后被调用的 ImageView changeImage = (ImageView) findViewById(R.id.animation_frame_img); changeImage.setBackgroundResource(R.anim.animation_frame);//xml配置文件 AnimationDrawable changeAnimation = (AnimationDrawable) changeImage.getBackground(); changeAnimation.start(); }
如果用纯代码实现frame animation 代码示如下
AnimationDrawable anim = new AnimationDrawable(); for (int i = 1; i <= 4; i++) { int id = getResources().getIdentifier("animation_frame_" + i, "drawable", getPackageName()); Drawable drawable = getResources().getDrawable(id); anim.addFrame(drawable, 300); } anim.setOneShot(false); image.setBackgroundDrawable(anim); anim.start();
- Drawable Animation
见上文 frame animation
最后说一下 apidemo的activity的淡入淡出和放大缩小动画入场
1.淡入淡出 配置文件
<alpha xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:fromAlpha="0.0" android:toAlpha="1.0" android:duration="@android:integer/config_longAnimTime" />
<translate xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator" android:fromXDelta="0" android:toXDelta="0" android:duration="@android:integer/config_longAnimTime" />
代码中调用
startActivity(new Intent(Animation.this, ApiDemosStudyActivity.class)); overridePendingTransition(R.anim.animation_fade,R.anim.animation_hold);
其中关于overridePendingTransition方法 sdk中有如下说明
Call immediately after one of the flavors of startActivity(Intent)
or finish
to specify an explicit transition animation to perform next.
2.zoom效果同样 只是xml配置有区别
发表评论
-
android2.3 api demo 学习系列(23)--App/Notification/StatusBarNotification
2012-07-07 19:51 1296apidemo-StatusBarNotification里面 ... -
android2.3 api demo 学习系列(22)--App/Notification/Notifying Service Controller
2012-07-06 14:56 1674因为还没有看到service的demo,这里先不对servic ... -
android2.3 api demo 学习系列(21)--App/Notification/Incoming Message
2012-07-06 11:55 2423现在我们开始学习android的Status Bar Noti ... -
android2.3 api demo 学习系列(20)--App/Menu
2012-07-06 09:58 1110现在来学习下menu的相关 ... -
android2.3 api demo 学习系列(19)--App/Intent and Launcher Shortcuts
2012-07-06 09:36 1060第一个demo:Intent,根据指定的类型,枚举出所有符合条 ... -
android2.3 api demo 学习系列(18)--App/Dialog
2012-07-06 09:13 954今天主要学习Dialog: 1、一般的dialog ... -
android2.3 api demo 学习系列(17)--App/Alarm/AlarmController and Alarm Service
2012-07-03 17:12 2145本次学习将apidemo中得两个demo:AlarmContr ... -
android2.3 api demo 学习系列(16)--App/Activity/Translucent and Blur activity
2012-07-03 11:47 1854本次同样是将apidemo中得两个demo合并起来学习:Tra ... -
android2.3 api demo 学习系列(15)--App/Activity/SetWallpaper
2012-07-03 11:00 1091本次示例我们整合了apidemo里面的两个demo:SetWa ... -
android2.3 api demo 学习系列(14)--App/Activity/Screen Orientation
2012-07-03 09:50 3079下面我们来学习下Screen Orientaiton的demo ... -
android2.3 api demo 学习系列(13)--App/Activity/Save & Restore
2012-07-02 17:29 1434前面文章android2.3 api demo 学习系 ... -
android2.3 api demo 学习系列(12)--App/Activity/Reorder Activitys
2012-07-02 16:45 957Reorder Activitys Demo主要是实现打开ac ... -
android2.3 api demo 学习系列(11)--App/Activity/Redirection
2012-07-02 15:52 828APIDEMO里面的redirection示例本身并没有新技术 ... -
android2.3 api demo 学习系列(10)--App/Activity/RecevieResult
2012-07-02 14:48 959在先前的文章 activity之间跳转传值 已经学习过这方面的 ... -
android2.3 api demo 学习系列(9)--App/Activity/QuickContactsDemo
2012-07-01 19:46 957现在我们来学习如何使用Content Provider来访问a ... -
android2.3 api demo 学习系列(8)--App/Activity/Preference State
2012-07-01 19:45 868android保存数据有很多种方式,其中最简单的就是使用Sha ... -
android2.3 api demo 学习系列(7)--App/Activity/Hello World
2012-06-29 14:03 1048学习android当然不能少了HelloWorld,接下来我们 ... -
android2.3 api demo 学习系列(6)--App/Activity/ForwardActivity
2012-06-29 13:50 798本次学习activity的跳转 1、构建intent ... -
android2.3 api demo 学习系列(5)--App/Activity/Dialog
2012-06-29 11:42 965前面我们已经学习了Custom Dialog 和 Custom ... -
android2.3 api demo 学习系列(4)--App/Activity/Custom Title
2012-06-29 11:26 1054android的标题栏默认是由android:lable定义的 ...
相关推荐
dlib-android-app See http://dlib.net for the main project documentation. See dlib-android for JNI lib. Refer to dlib-android/jni/jnilib_ex Grap the source $ git clone ...
安卓串口Demo程序 基于谷歌提供的源码android-serialport-api-android-serialport-api
2018年6月20最新编译React-Native官方demo,可直接运行版本。对应执行如下命令: 1.D:\reactnative\RNTester> react-native bundle --platform android ...2.D:\reactnative\RNTester\android>gradlew :app:installDebug
cordova-plugin-app-update App updater for Cordova/PhoneGap Demo Try it yourself: Just clone and install this demo. cordova-plugin-app-update-DEMO :tada: 如果喜欢它,请别忘了给我一颗鼓励的星 Support ...
这是很据android-serialport-api 自己简化的一个demo ,可以使用。原来android-serial-api的程序很多人反映都不能使用,所以自己写了这个,只有一个activity,可以做为你的学习参考。
WebRTCDemo-master_android-studio,webrtcdemo,p2p,android-studio编译
准备工作$ npm install启动服务找到对应的实例代码,然后启动 所在目录的 server/app.js如node ./src/upfiles-demo/demo-a1-form/server/app.jsnode ./src/upfiles-demo/demo-a2-formdata/server/app.jsnode ./src/...
可使用不同的图片作为地图...//下载demo http://mapp.android-libraries.com/download //学习地图 http://www.67tgb.com/?p=610 图片切割 http://www.67tgb.com/?p=597 http://mapp.android-libraries.com/slicingtool/
因为工作中要使用 Android Camera2 API 来实现相机功能,但因为Camera2比较复杂,网上资料也比较乱,有一定入门门槛,所以花了几天时间系统研究了下,这个项目就是我研究的成果。 其中包括一个自己写的Camera2的Demo...
由于最近在做智能家居方向的产品,需要在App上对机器人实现一个简单的语音控制,于是开始寻找相应的解决方案,由于某种原因,google自己的语音识别API并不能在国内发挥作用,所以我们选择国内的科大讯飞语音识别服务...
Provide Android animation API/Demo
android 项目 开发 demo <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.demo" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:...
Android串口操作,简化android-serialport-api的demo(附源码) 我把文中的源码导入 android studio 源码来自谷歌:android-serialport-api 涉及到的 jni 开发可以参考:【Android 应用开发】Android 开发 之 JNI...
OpenSAML-ref-project-demo-v3 这一个使用OpenSAML库的示例项目: 一个很简单的网址,其充当SP;同时该项目还包括一个很简单的IDP; SAML协议的交互将在这二者之间展开。项目启动之后,访问如下网址: ...
JavaScript人脸识别库Face-api.js的示例,无需安装nodejs,iis本地直接看效果。注意调用摄像头不能用IP访问,只能localhost,远程预览需要HTTPS;iis无扩展名文件若出现404,需在mime类型中添加扩展名【.】类型...
ci-demo-app-homebrew-tap CI演示应用程序的自制方法 安装 注册水龙头: brew tap embano1/ci-demo-app git@github.com:embano1/ci-demo-app-homebrew-tap 注意:如果您没有使用ssh设置git,您也可以使用...
这是android 2.3及2.3以后才能用的Sip (网络电话)相关接口使用的例子,实现了基本的网络电话功能(呼叫及被呼叫),用的是Android提供的编程接口。
DroidDrop - Remote Logging DroidDrop Remote logging give Android Developers the ability to log data from their applications to a drop on drop.io. ...Get a developer API Key from drop.io (free
android模拟launcher公司项目demo源码:可以学习到 自定义组件(图片和文字帮定),启动其它包内的程序.....................希望同仁好好利用!
android demo 的例子 用来学习android的效果 ,view 都是很好的帮助 还是中文的 通俗易懂 谢谢