android gallary demo

两年没写过了,这两年我都干了些啥。。。。。

项目需求,要做一个头像滑动切换( demo源码在 http://git.oschina.net/agilest/gallary-demo),android刚接触,不是很熟悉,网上看了有很多类似仿iOS CoverFlow的组件(http://www.oschina.net/p/android-coverflow)。看了一下效果跟我要的差不多一致,就是当前图片正面显示,左右两侧的Y轴旋转。但是这个demo在滑动后Y轴旋转角度貌似有点麻烦(又是计算中心点,又是各种加减乘除),同时好像还有bug(滑动过快会导致正负出现计算错误)。研究了一番,发现其实很简单,左侧的图片旋转80度,右侧的图片旋转-80度,只要找到每一张的前一张(往左侧滑动时左侧那张)和下一张(往左侧滑动时右侧那张),然后让他们分别延Y轴旋转80盒-80就可以了,如何找到这两张呢?其实很简单:

public View getView(int position, View convertView, ViewGroup parent) {
		ImageView i = mImages[position % mImages.length];
		i.setTag(position);
		return i;
	}

 给每个ImageView设置一个tag,

然后在滑动时判断tag的值就可以了:

protected boolean getChildStaticTransformation(View child, Transformation t) {
		t.clear();
		t.setTransformationType(Transformation.TYPE_MATRIX);

		int childIndex = Integer.parseInt(child.getTag().toString());
		int currentIndex = Integer.parseInt(this.getSelectedView().getTag().toString());
		if(childIndex==currentIndex){
			transformImageBitmap((ImageView) child,t,0);
		}else if(childIndex<currentIndex){
			transformImageBitmap((ImageView) child,t,mMaxRotationAngle);
		}else{
			transformImageBitmap((ImageView) child,t,-mMaxRotationAngle);
		}

		return true;
	}

猜你喜欢

转载自tiamo.iteye.com/blog/2256600
今日推荐