我有一系列的图片。我希望用户可以通过左右滑动来查看图像。我知道画廊视图,但我想在Android画廊应用程序中内置的东西,用户幻灯片图像。
发布于 2012-01-26 16:06:11
尝试在您的代码中使用Flipper ...
flipper = (ViewFlipper) findViewById(R.id.flipper);
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
int layouts[] = new int[]{ R.layout.first, R.layout.second, R.layout.third, R.layout.fourth,
R.layout.fifth, R.layout.sixth, R.layout.seventh, R.layout.eighth, R.layout.nineth, R.layout.tenth,
R.layout.eleventh, R.layout.twelveth, R.layout.thirteen };
for (int layout : layouts)
flipper.addView(inflater.inflate(layout, null));所有幻灯片都是用xml描述的……
public boolean onTouch(View view, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
fromPosition = event.getX();
break;
case MotionEvent.ACTION_UP:
float toPosition = event.getX();
if (fromPosition > toPosition)
{
flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.go_next_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.go_next_out));
flipper.showNext();
}
else if (fromPosition < toPosition)
{
flipper.setInAnimation(AnimationUtils.loadAnimation(this,R.anim.go_prev_in));
flipper.setOutAnimation(AnimationUtils.loadAnimation(this,R.anim.go_prev_out));
flipper.showPrevious();
}
default:
break;
}
return true;
}滑动
https://stackoverflow.com/questions/9014740
复制相似问题