问题描述
我有图像列表.我希望用户可以通过向左和向右滑动来看到图像.我知道画廊的视图,但我想要诸如用户滑动图像的Android Gallery应用程序之类的东西.
推荐答案
尝试在您的代码中使用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; }
滑动
问题描述
I have list of images. I want that user can see images by sliding left and right. I know about Gallery view but I want something like built in Android Gallery application where user slides images.
推荐答案
Try to use Flipper in your code...
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));
all slides are described in 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; }
sliding