首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用GestureDetector android的Fling

使用GestureDetector android的Fling
EN

Stack Overflow用户
提问于 2015-06-20 01:12:46
回答 2查看 38关注 0票数 0
代码语言:javascript
复制
public boolean onFling(MotionEvent e1, MotionEvent e2,
                float velocityX, float velocityY) {
            // TODO Auto-generated method stub
            if(velocityX<-10.0f)
            {
                mCurrentStateLayout = mCurrentStateLayout == 0 ? 1 : 0;
                switchLayoutStateTo(mCurrentStateLayout);
            }
            return true;    
        }           
    });

语句mCurrentStateLayout = mCurrentStateLayout == 0?1: 0;是什么意思?

EN

回答 2

Stack Overflow用户

发布于 2015-06-20 01:18:58

代码语言:javascript
复制
mCurrentStateLayout = mCurrentStateLayout == 0 ? 1 : 0;

这是Java中的ternary操作符。它本质上是if else语句的简写。

如果mCurrentStateLayout 等于0,则该语句为true,并为mCurrentStateLayout赋值1。

如果mCurrentStateLayout is not等于0,则该语句为false,并为mCurrentStateLayout赋值0。

票数 1
EN

Stack Overflow用户

发布于 2015-06-20 02:15:38

在代码中显示它。这是你粘贴在这里的代码的模拟:

代码语言:javascript
复制
public boolean onFling(MotionEvent e1, MotionEvent e2,
                float velocityX, float velocityY) {
            // TODO Auto-generated method stub
            if(velocityX<-10.0f)
            {
                if (mCurrentStateLayout == 0) {
                    mCurrentStateLayout = 1;
                } else {
                    mCurrentStateLayout = 0;
                }
                switchLayoutStateTo(mCurrentStateLayout);
            }
            return true;    
        }           
    });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30943694

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档