【问题标题】:Viewflipper not flinging when child view is webview当子视图是 webview 时,Viewflipper 不扔
【发布时间】:2012-06-23 07:06:19
【问题描述】:

我有一个 viewflipper,其子项是动态创建的,它们可以是 textview 或 webview。当孩子是 TextView 时,视图翻转器会正确抛出,但当孩子是 webview 时不会抛出。

【问题讨论】:

  • 你的视图应该是相同类型的假设如果你直接在视图翻转器中使用 textview 比所有都应该是 textview 并且如果你想使用不同的视图而不是用于所有动态视图一个父线性或任何其他每个添加视图的布局视图

标签: android viewflipper


【解决方案1】:

我也遇到过同样的问题。我面临的问题是在一个视图中我在另一个视图中有一个 webview 我在第一个视图中有两个图像视图我试图交换视图没有更改为第二个视图我使用触摸事件在视图之间进行更改,但这没有发生。后来我也为 webview 使用了触摸事件,然后我可以在视图之间交换。

用于切换触摸事件的代码如下。

public boolean onTouchEvent(MotionEvent touchevent)
{
switch (touchevent.getAction())
{
    // when user first touches the screen to swap
    case MotionEvent.ACTION_DOWN: 
    {
        lastX = touchevent.getX();
        break;
    }
    case MotionEvent.ACTION_UP: 
    {
        float currentX = touchevent.getX();
        // if left to right swipe on screen
        if (lastX < currentX) 
        {
            // If no more View/Child to flip
            if (viewFlipper.getDisplayedChild() == 0)
                break;
            // set the required Animation type to ViewFlipper
            // The Next screen will come in form Left and current Screen will go OUT from Right 
            viewFlipper.setInAnimation(this, R.anim.in_from_left);
            viewFlipper.setOutAnimation(this, R.anim.out_to_right);
            // Show the next Screen
            viewFlipper.showNext();
        }
        // if right to left swipe on screen
        if (lastX > currentX)
        {
            if (viewFlipper.getDisplayedChild() == 1)
                break;
            // set the required Animation type to ViewFlipper
            // The Next screen will come in form Right and current Screen will go OUT from Left 
            viewFlipper.setInAnimation(this, R.anim.in_from_right);
            viewFlipper.setOutAnimation(this, R.anim.out_to_left);
            // Show The Previous Screen
            viewFlipper.showPrevious();
        }
        break;
    }
}
return false;

}

为您的 webview setOnTouchListener 使用相同的代码,以便它可以为您工作。

希望对你有所帮助。

感谢和问候, G.Shashank Reddy。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多