我在这里使用视图寻呼机设置onTouchListner
。
我想在View Viewr上进行简单点击时,它应隐藏或显示操作栏和其他布局,并在再次触摸时显示它们。我还想使用Sliding effect
视图寻呼机。
这是我到目前为止所做的。
viewPager.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
onTouchEvent(event);
return false;
}
});
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN: {
downX = event.getX();
downY = event.getY();
return true;
}
case MotionEvent.ACTION_UP: {
upX = event.getX();
upY = event.getY();
float deltaX = downX - upX;
float deltaY = downY - upY;
// swipe horizontal?
if (Math.abs(deltaX) > MIN_DISTANCE) {
// left or right
if (deltaX < 0) {
Toast("Left to right");
openPreviousPage();
return true;
}
if (deltaX > 0) {
Toast("ight to left");
openNextPage();
return true;
}
} else {
if (Math.abs(deltaX) < 15) {
toggleFullScreen();
}
}
return true;
}
}
return false;
}
使用SystemUiHider
隐藏操作栏和其他布局。
以下是我要隐藏的内容
mSystemUiHider = SystemUiHider.getInstance(this, bottomRL, HIDER_FLAGS);
mSystemUiHider.setup();
mSystemUiHider
.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
// Cached values.
int mControlsHeight;
int mShortAnimTime;
@Override
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
public void onVisibilityChange(boolean visible) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
// If the ViewPropertyAnimator API is available
// (Honeycomb MR2 and later), use it to animate the
// in-layout UI controls at the bottom of the
// screen.
if (mControlsHeight == 0) {
mControlsHeight = bottomRL.getHeight();
}
if (mShortAnimTime == 0) {
mShortAnimTime = getResources().getInteger(
android.R.integer.config_shortAnimTime);
}
bottomRL.animate()
.translationY(visible ? 0 : mControlsHeight)
.setDuration(mShortAnimTime);
} else {
if (visible) {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
bottomRL.setLayoutParams(params);
bottomRL.setVisibility(View.VISIBLE);
// getActionBar().show();
} else {
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.MATCH_PARENT,
RelativeLayout.LayoutParams.MATCH_PARENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
viewPager.setLayoutParams(params);
getActionBar().hide();
viewPager.setVisibility(View.GONE);
}
}
if (visible) {
// Schedule a hide().
// delayedHide(AUTO_HIDE_DELAY_MILLIS);
}
}
});
问题在于,当我触摸查看寻呼机时,它会隐藏操作栏和其他布局,即现在我处于全屏模式。但是现在,如果我尝试滑动视图寻呼机,它首先显示操作栏,然后在滑动后滑动到下一个屏幕
请帮助我解决这个问题。 提前谢谢。