安卓画廊般的图像滑块[英] Android Gallery like image slider

本文是小编为大家收集整理的关于安卓画廊般的图像滑块的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

我有图像列表.我希望用户可以通过向左和向右滑动来看到图像.我知道画廊的视图,但我想要诸如用户滑动图像的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;
}

滑动

本文地址:https://www.itbaoku.cn/post/102354.html

问题描述

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