亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

當我展開動畫還沒結束,執行收起動畫的時候,有的button沒有收回,誰幫忙看看


package com.example.animationdemo;

import java.sql.Date;
import java.sql.Time;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.util.TimeUtils;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.BounceInterpolator;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;


public class MainActivity extends Activity {
?? ?ImageView img;
?? ?int[] imgList = {R.id.menuBtn1,R.id.menuBtn2,R.id.menuBtn3,R.id.menuBtn4,R.id.menuBtn5,R.id.menuBtn6,R.id.menuBtn7,R.id.menuBtn8,};
?? ?ArrayList<ImageButton> imgBtnList = new ArrayList<ImageButton>();
?? ?boolean isEx? = false;
?? ?float winHeigth;
??? @Override
??? protected void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.activity_main);
??????? img = (ImageView) findViewById(R.id.anmImg);
??????? for (int i = 0; i < imgList.length; i++) {
?? ??? ??? ?ImageButton imgBtn = (ImageButton) findViewById(imgList[i]);
?? ??? ??? ?imgBtnList.add(imgBtn);
?? ??? ?}
??????? winHeigth = getResources().getDisplayMetrics().heightPixels;
??? }

??? @Override
??? public boolean onCreateOptionsMenu(Menu menu) {
??????? // Inflate the menu; this adds items to the action bar if it is present.
??????? getMenuInflater().inflate(R.menu.main, menu);
??????? return true;
??? }

??? @Override
??? public boolean onOptionsItemSelected(MenuItem item) {
??????? // Handle action bar item clicks here. The action bar will
??????? // automatically handle clicks on the Home/Up button, so long
??????? // as you specify a parent activity in AndroidManifest.xml.
??????? int id = item.getItemId();
??????? if (id == R.id.action_settings) {
??????????? return true;
??????? }
??????? return super.onOptionsItemSelected(item);
??? }
?? ?
??? public void start(View view){
?? ??? ?ObjectAnimator.ofFloat(img, "translationX", 0,100F).setDuration(2000).start();
?? ??? ?PropertyValuesHolder animator1 = PropertyValuesHolder.ofFloat("translationY", 0,100F);
?? ??? ?PropertyValuesHolder animator2 = PropertyValuesHolder.ofFloat("rotation", 0,360F);
?? ??? ?ObjectAnimator.ofPropertyValuesHolder(img, animator1,animator2).start();

?? ??? ?ObjectAnimator a1 = ObjectAnimator.ofFloat(img, "translationX", 0,100F).setDuration(2000);
?? ??? ?ObjectAnimator a2 = ObjectAnimator.ofFloat(img, "translationY", 0,100F).setDuration(2000);
?? ??? ?ObjectAnimator a3 = ObjectAnimator.ofFloat(img, "rotation", 0,360F).setDuration(2000);
//?? ??? ?AnimatorSet set = new AnimatorSet();
//?? ??? ?set.play(a1).with(a2);
//?? ??? ?set.play(a3).after(a1);
//?? ??? ?set.start();
??? }
?? ?
??? public void menuOnClick(View v){
?? ??? ?switch (v.getId()) {
?? ??? ?case R.id.menuBtn8:
?? ??? ??? ?if (isEx) {
?? ??? ??? ??? ?foldMenu();
?? ??? ??? ??? ?isEx = false;
?? ??? ??? ?}else {
?? ??? ??? ??? ?unfoldMenu();
?? ??? ??? ??? ?isEx = true;
?? ??? ??? ?}
?? ??? ??? ?break;

?? ??? ?default:
?? ??? ??? ?Toast.makeText(this, "menu"+v.toString(), Toast.LENGTH_SHORT).show();
?? ??? ??? ?break;
?? ??? ?}
??? }

?? ?private void unfoldMenu() {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?ImageButton orderBtn = imgBtnList.get(imgBtnList.size()-1);
?? ??? ?for (int i = 0; i < imgBtnList.size() - 1; i++) {
?? ??? ??? ?ImageButton menu = imgBtnList.get(i);
?? ??? ??? ?float moveLen = (winHeigth - orderBtn.getTranslationY()) / 10 * (i+1);
?? ??? ??? ?float time = (winHeigth - orderBtn.getTranslationY()) / 10/winHeigth*3000;
?? ??? ??? ?float startY;
?? ??? ??? ?if (i == 0) {
?? ??? ??? ??? ?startY = imgBtnList.get(imgBtnList.size()-1).getTranslationY();
?? ??? ??? ?}else {
?? ??? ??? ??? ?startY = imgBtnList.get(i-1).getY();
?? ??? ??? ?}
?? ??? ??? ?ObjectAnimator animator1 = ObjectAnimator.ofFloat(menu, "translationY", startY,moveLen+orderBtn.getTranslationY());
//?? ??? ??? ?animator1.setInterpolator(new BounceInterpolator());
?? ??? ??? ?animator1.setStartDelay((long) time*(i+1));
?? ??? ??? ?animator1.setDuration((long) time);
?? ??? ??? ?animator1.start();
?? ??? ?}
?? ?}

?? ?private void foldMenu() {
?? ??? ?// TODO Auto-generated method stub
?? ??? ?long start = System.currentTimeMillis();
?? ??? ?for (int i = 0; i < imgBtnList.size() - 1; i++) {
?? ??? ??? ?ImageButton menu = imgBtnList.get(i);
?? ??? ??? ?menu.clearAnimation();
?? ??? ??? ?float moveLen = imgBtnList.get(imgBtnList.size()-1).getTranslationY();
?? ??? ??? ?ObjectAnimator animator1 = ObjectAnimator.ofFloat(menu, "translationY", menu.getTranslationY(),moveLen);
?? ??? ??? ?animator1.setDuration((long) (3000*((menu.getTranslationY()-moveLen)/winHeigth)));
?? ??? ??? ?animator1.start();
?? ??? ?}
?? ??? ?long end = System.currentTimeMillis();
?? ??? ?Log.i("test", "Time:"+(end-start));
?? ?}
}

正在回答

2 回答

在動畫監聽器里面,動畫開始時設置展開菜單按鈕為不可點擊啊,動畫結束后設置為可點擊

0 回復 有任何疑惑可以回復我~

menu 是什么鬼?

boolean變量默認先為true,在打開的之后設置為false,執行收回動畫之后設置為true,你好像寫反了..

0 回復 有任何疑惑可以回復我~
#1

囧恩_姜戈 提問者

Boolean我寫的是是否展開,沒問題啊,menu。。。這個寫的不是一種菜單?有問題?
2016-11-23 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
Android屬性動畫賞析
  • 參與學習       37226    人
  • 解答問題       77    個

本次課程,將向你介紹如何使用屬性動畫做出更好的動畫

進入課程

當我展開動畫還沒結束,執行收起動畫的時候,有的button沒有收回,誰幫忙看看

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號