此情况出现错误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;
}
答案 0 :(得分: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))