//设置图片宽度
private void InitImageView() {
// 只是改变宽度而已cursor = (ImageView) findViewById(R.id.cursor);
int width = getWindowManager().getDefaultDisplay().getWidth();
width /= 3;
LinearLayout.LayoutParams params = (android.widget.LinearLayout.LayoutParams) cursor
.getLayoutParams();
params.width = width;
cursor.setLayoutParams(params);
}
//viewpager切换动画
private class OnPageChangeListener implements
android.support.v4.view.ViewPager.OnPageChangeListener {
@Override
public void onPageScrollStateChanged(int arg0) {
// TODO Auto-generated method stub
}
@Override
public void onPageScrolled(int arg0, float arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public void onPageSelected(int arg0) {
Animation animation = null;
switch (arg0) {
case 0:
if (state == 1) {// 1---》0
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 1,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
} else if (state == 2) {// 2---》0
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
}
break;
case 1:
if (state == 0) {// 0---》1
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 1,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
} else if (state == 2) {// 2---》1
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 1,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
}
break;
case 2:
if (state == 0) {// 0---》2
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
} else if (state == 1) {// 1--》2
animation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, 1,
Animation.RELATIVE_TO_SELF, 2,
Animation.RELATIVE_TO_SELF, 0,
Animation.RELATIVE_TO_SELF, 0);
}
break;
}
state = arg0;
animation.setFillAfter(true);// True:图片停在动画结束位置
animation.setDuration(300);
cursor.startAnimation(animation);
}
}