0

在这种情况下会出现“应以静态方式访问if((detail.VISIBLE) && (pod.GONE) && (photo.GONE)) 静态字段”的错误View.GONE

...

public boolean onScroll(MotionEvent e1, MotionEvent e2, 
                        float velocityX, float velocityY) {

    final RelativeLayout detail = (RelativeLayout) findViewById(R.id.layout_detail);
    final RelativeLayout photo = (RelativeLayout) findViewById(R.id.layout_detail_photo);
    final RelativeLayout pod = (RelativeLayout) findViewById(R.id.layout_detail_pod);
    final ToggleButton btn_detail = (ToggleButton) findViewById(R.id.btn_detail);
    final ToggleButton btn_pod = (ToggleButton) findViewById(R.id.btn_pod);
    final ToggleButton btn_photo = (ToggleButton) findViewById(R.id.btn_photo);

    // right to left swipe
    if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && 
        Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
        Toast.makeText(this, "Left Swipe", Toast.LENGTH_SHORT).show();
        if((detail.VISIBLE) && (pod.GONE) && (photo.GONE)) {
            detail.setVisibility(View.GONE);
            photo.setVisibility(View.GONE);
            pod.setVisibility(View.VISIBLE);
            btn_photo.setSelected(false);
            btn_pod.setSelected(true);
            btn_detail.setSelected(false);
        }
    }  

    // left to right swipe
    else if (e2.getY() - e1.getY() > SWIPE_MIN_DISTANCE && 
             Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
         Toast.makeText(this, "Right Swipe", Toast.LENGTH_SHORT).show();
    }
    return true;
}
4

1 回答 1

2

VISIBLE, GONE, 和INVISIBLE是 上的静态数据成员View。它们是常数。您将它们视为小部件的字段或属性,这可能不是您想要的。

我建议改变:

if((detail.VISIBLE) && (pod.GONE) && (photo.GONE))

至:

if((detail.getVisibility()==View.VISIBLE) && (pod.getVisibility()==View.GONE) && (photo.getVisibiilty()==View.GONE))
于 2013-07-16T23:13:17.417 回答