Android Gallery like image slider

£可爱£侵袭症+ 提交于 2019-12-13 12:13:24

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/9014740/android-gallery-like-image-slider

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!