Android图库就像图片滑块

时间:2012-01-26 06:44:36

标签: android image gallery

我有图像列表。我希望用户可以通过左右滑动来查看图像。我知道Gallery视图但我想要内置Android Gallery应用程序,用户可以在其中滑动图像。

1 个答案:

答案 0 :(得分:4)

尝试在代码中使用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;
}

滑动

相关问题