引导页面的移动箭头效果 guide arrow animation

要实现类似效果

引导页面的移动箭头效果 guide arrow animation_第1张图片

由于动画是非平滑的,所以不能用平移的方式来实现,这里就定时去更新在父布局的位置来是实现

先看布局代码



        

            

            

            

        

        
    
实现代码:

@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.new_guide);


		swipeView = findViewById(R.id.swipe_layout);
		iv1 = (ImageView) findViewById(R.id.guide_arrow_1);
		iv2 = (ImageView) findViewById(R.id.guide_arrow_2);
		iv3 = (ImageView) findViewById(R.id.guide_arrow_3);

		iv1.getViewTreeObserver().addOnGlobalLayoutListener(
				new OnGlobalLayoutListener() {

					@Override
					public void onGlobalLayout() {
						// TODO Auto-generated method stub
						iv1Left = iv1.getLeft();
						iv1Height = iv1.getHeight();
						iv1Right = iv1.getRight();
						iv1Top = iv1.getTop();
						iv1Temp = iv1Top;
						iv1.getViewTreeObserver().removeGlobalOnLayoutListener(
								this);
						handler.post(arrowRunable);
					}
				});
	}

	class ArrowRunable implements Runnable {

		@Override
		public void run() {
			// TODO Auto-generated method stub
			iv1.layout(iv1Left, iv1Temp - iv1Height-1, iv1Right, iv1Temp-1);
			iv2.layout(iv1Left, iv1Temp, iv1Right, iv1Temp + iv1Height);
			iv3.layout(iv1Left, iv1Temp + iv1Height+1, iv1Right, iv1Temp + 2*iv1Height+1);
			iv1Temp -= iv1Height;
			if (iv1Temp + 3 * iv1Height < 0) {
				iv1Temp = iv1Top;
			}
			handler.postDelayed(this, 180);
		}
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		if (handler != null && arrowRunable != null) {
			Logger.d("removeCallbacks");
			handler.removeCallbacks(arrowRunable);
		}
	}
ok,这样应该就可以了,大家有更好的,欢迎交流


你可能感兴趣的:(Android)