安卓中級教程(8):pathbutton中的animation.java研究(1)
- src/geniuz/myPathbutton/myAnimations.java
- package geniuz.myPathbutton;
- import java.util.ArrayList;
- import java.util.List;
- import com.nineoldandroids.animation.Animator;
- import com.nineoldandroids.animation.Animator.AnimatorListener;
- import com.nineoldandroids.view.ViewPropertyAnimator;
- import android.util.Log;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.animation.Animation;
- import android.view.animation.Animation.AnimationListener;
- import android.view.animation.AnticipateInterpolator;
- import android.view.animation.OvershootInterpolator;
- import android.view.animation.RotateAnimation;
- import android.view.animation.TranslateAnimation;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout.LayoutParams;
- import android.widget.RelativeLayout;
- import static com.nineoldandroids.view.ViewPropertyAnimator.animate;
- public class myAnimations {
- public final int R; // 半徑
- public static byte RIGHTBOTTOM = 1, CENTERBOTTOM = 2, LEFTBOTTOM = 3,
- LEFTCENTER = 4, LEFTTOP = 5, CENTERTOP = 6, RIGHTTOP = 7,
- RIGHTCENTER = 8;
- private int pc; // 位置代號
- private ViewGroup clayout; // 父laoyout
- private final int amount; // 有幾多個按鈕
- private double fullangle = 180.0;// 在幾大嘅角度內排佈
- private byte xOri = 1, yOri = 1; // x、y值嘅方向,即系向上還是向下
- private boolean isOpen = false;// 记录是已经打开还是关闭
- private List<ViewPropertyAnimator> viewAnimators = new ArrayList<ViewPropertyAnimator>();
- /**
- * 構造函數
- *
- * @param comlayout
- * 包裹彈出按鈕嘅layout
- * @param poscode
- * 位置代號,分別對應RIGHTBOTTOM、CENTERBOTTOM、LEFTBOTTOM、LEFTCENTER、
- * LEFTTOP、CENTERTOP、RIGHTTOP、RIGHTCENTER
- * @param radius
- * 半徑
- */
- public myAnimations(ViewGroup comlayout, int poscode, int radius) {
- this.pc = poscode;
- this.clayout = comlayout;
- this.amount = clayout.getChildCount();
- this.R = radius;
- // 初始化动画,每个view对应一个animator
- for (int i = 0; i < amount; i++) {
- View childAt = clayout.getChildAt(i);
- ViewPropertyAnimator anim = animate(childAt);
- viewAnimators.add(anim);
- }
- if (poscode == RIGHTBOTTOM) { // 右下角
- fullangle = 90;
- xOri = -1;
- yOri = -1;
- } else if (poscode == CENTERBOTTOM) {// 中下
- fullangle = 180;
- xOri = -1;
- yOri = -1;
- } else if (poscode == LEFTBOTTOM) { // 左下角
- fullangle = 90;
- xOri = 1;
- yOri = -1;
- } else if (poscode == LEFTCENTER) { // 左中
- fullangle = 180;
- xOri = 1;
- yOri = -1;
- } else if (poscode == LEFTTOP) { // 左上角
- fullangle = 90;
- xOri = 1;
- yOri = 1;
- } else if (poscode == CENTERTOP) { // 中上
- fullangle = 180;
- xOri = -1;
- yOri = 1;
- } else if (poscode == RIGHTTOP) { // 右上角
- fullangle = 90;
- xOri = -1;
- yOri = 1;
- } else if (poscode == RIGHTCENTER) { // 右中
- fullangle = 180;
- xOri = -1;
- yOri = -1;
- }
- }
- private class AnimListener implements AnimatorListener {
- private View target;
- public AnimListener(View _target) {
- target = _target;
- }
- @Override
- public void onAnimationStart(Animator animation) {
- }
- @Override
- public void onAnimationEnd(Animator animation) {
- if (!isOpen) {
- target.setVisibility(View.INVISIBLE);
- }
- }
- @Override
- public void onAnimationCancel(Animator animation) {
- // TODO Auto-generated method stub
- }
- @Override
- public void onAnimationRepeat(Animator animation) {
- // TODO Auto-generated method stub
- }
- }
- /**
- * 彈幾個按鈕出嚟
- *
- * @param durationMillis
- * 用幾多時間
- */
- public void startAnimationsIn(int durationMillis) {
- isOpen = true;
- for (int i = 0; i < clayout.getChildCount(); i++) {
- final LinearLayout inoutimagebutton = (LinearLayout) clayout
- .getChildAt(i);
- double offangle = fullangle / (amount - 1);
- final double deltaY, deltaX;
- if (pc == LEFTCENTER || pc == RIGHTCENTER) {
- deltaX = Math.sin(offangle * i * Math.PI / 180) * R;
- deltaY = Math.cos(offangle * i * Math.PI / 180) * R;
- } else {
- deltaY = Math.sin(offangle * i * Math.PI / 180) * R;
- deltaX = Math.cos(offangle * i * Math.PI / 180) * R;
- }
- ViewPropertyAnimator viewPropertyAnimator = viewAnimators.get(i);
- viewPropertyAnimator.setListener(null);
- inoutimagebutton.setVisibility(View.VISIBLE);
- viewPropertyAnimator.x(
- (float) (inoutimagebutton.getLeft() + xOri * deltaX)).y(
- (float) (inoutimagebutton.getTop() + yOri * deltaY));
- }
- }
- /**
- * 收埋幾個按鈕入去
- *
- * @param durationMillis
- * 用幾多時間
- */
- public void startAnimationsOut(int durationMillis) {
- isOpen = false;
- for (int i = 0; i < clayout.getChildCount(); i++) {
- final LinearLayout inoutimagebutton = (LinearLayout) clayout
- .getChildAt(i);
- ViewPropertyAnimator viewPropertyAnimator = viewAnimators.get(i);
- viewPropertyAnimator.setListener(null);
- viewPropertyAnimator.x((float) inoutimagebutton.getLeft()).y(
- (float) inoutimagebutton.getTop());
- viewPropertyAnimator
- .setListener(new AnimListener(inoutimagebutton));
- }
- }
- /**
- * 獲取位置代碼(其實貌似都冇乜用)
- */
- public int getPosCode() {
- return this.pc;
- }
- /**
- * 自轉函數(原本就有嘅靜態函數,未實體化都可以調用)
- *
- * @param fromDegrees
- * 從幾多度
- * @param toDegrees
- * 到幾多度
- * @param durationMillis
- * 轉幾耐
- */
- public static Animation getRotateAnimation(float fromDegrees,
- float toDegrees, int durationMillis) {
- RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees,
- Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
- 0.5f);
- rotate.setDuration(durationMillis);
- rotate.setFillAfter(true);
- return rotate;
- }
- }
- Desktop version
安卓中級教程(8):pathbutton中的animation.java研究(1)的更多相关文章
- 安卓中級教程(3):ScrollView
以上是scrollview的圖例,可見srollview是一種滑動功能的控件,亦是非常常見的控件. 一般寫法如下: package com.mycompany.viewscroller; import ...
- 安卓中級教程(9):pathbutton中的animation.java研究(2)
src/geniuz/myPathbutton/composerLayout.java package geniuz.myPathbutton; import com.nineoldandroids. ...
- 安卓中級教程(10):@InjectView
package com.example.android.db01; import android.app.Activity; import android.content.ContentValues; ...
- 安卓中級教程(5):ScrollView與refreshable之間的設置
設置向下拉動更新. package com.mycompany.Scroll_test; import android.app.*; import android.os.*; import andro ...
- 安卓中級教程(4):ScrollView與ListView之間的高度問題
在scrollView中加插ListView是一個大難題.其中一個難題是Listview的高度難以計算,輸出效果往往強差人意,就讓我們看看當中的問題 . <LinearLayout xmlns: ...
- 安卓中級教程(6):annotation的基本用法
package com.example.ele_me.activity; import android.annotation.SuppressLint; import android.app.Acti ...
- 安卓中級教程(1):@InjectView
package com.mycompany.hungry; import android.annotation.SuppressLint; import android.app.Activity; i ...
- 安卓中級教程(11):深入研究餓了麼的各個java檔運作關係(1)
package com.example.ele_me.activity; import android.annotation.SuppressLint; import android.app.Acti ...
- 安卓中級教程(7):annotation中的 public @interface的用法
package com.example.ele_me.util; import java.lang.annotation.Retention; import java.lang.annotation. ...
随机推荐
- Android滑动菜单特效实现,仿人人客户端侧滑效果,史上最简单的侧滑实现
http://blog.csdn.net/guolin_blog/article/details/8714621 http://blog.csdn.net/lmj623565791/article/d ...
- iOS开发——高级篇——iPad开发、iPad开发中的modal
一.iPad简介 1.什么是iPad一款苹果公司于2010年发布的平板电脑定位介于苹果的智能手机iPhone和笔记本电脑产品之间跟iPhone一样,搭载的是iOS操作系统 2.iPhone和iPadi ...
- mysql取前取后
SELECT * FROM (SELECT * FROM 表 WHERE id<居中的ID ORDER BY id DESC LIMIT 5) as A UNION all SELECT * F ...
- [Keygen]IntelliJ IDEA 14.1.7
IntelliJ IDEA 14.1.7 Keygen package com.candy.keygen.intelliJIdea; import java.math.BigInteger; impo ...
- dp 走格子问题
问题: 一个5x8的格子,想从左下角走到右上角,求最短路径,共有多少种走法. 思路: 因为是求最短路径,所以,只会往右往上走. 我们可以把棋盘的左下角看做二维坐标的原点(0,0),把棋盘的右上角看做二 ...
- VMware中的Ubuntu网络设置
网络配置: VMware安装后会有两个默认网卡,分别是VMnet8(192.168.83.1)和VMnet1(192.168.19.1),当然不同的机器上,这两个网卡的 IP会不同的.在windows ...
- BZOJ 1770: [Usaco2009 Nov]lights 燈
Description 一个图,对一个点进行操作会改变这个点及其相邻的点的状态,问全部变成黑色至少需要几次.数据保证有解. Sol Meet in middle. 我一开始写个高斯消元,发现有两个点过 ...
- linux git安装及配置(包括更新)
1.在终端运行命令 sudo apt-get install git 2.查看版本号 git --version (若不是最新可更新 自选) 更新提示: sudo add-apt-repositor ...
- 微信支付JSAPI模式及退款CodeIgniter集成篇
微信支付接口文档:https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_1 首先你得知道这个jsapi是不能离开微信进行调用支付的,明白 ...
- Fiddler响应post的请求 request body里面填写什么?
若是想传json格式的数据,请求头可以这样写:(应该先勾选 post,然后写上正确滴请求地址)User-Agent: Fiddler Host: localhost:1455 <span sty ...