我尝试使用与Viber界面(讨论页面)相同的导航样式,而不使用SlidingMenu
等第三方库。
我认为他们已经使用SlidingPaneLayout
来实现这个好效果,但是当我尝试编码时,我注意到最后一个窗格总是超过秒。
我的问题:
SlidingPaneLayout
吗? 左窗格
右窗格
答案 0 :(得分:2)
首先在类
中声明所有变量/** Sliding Menu */
boolean alreadyShowing = false;
private int windowWidth;
private Animation animationClasses;
private RelativeLayout classesSlider;
LayoutInflater layoutInflaterClasses;
然后在onCreate方法中声明这个,这将帮助你获得屏幕的高度和宽度
Display display = getWindowManager().getDefaultDisplay();
windowWidth = display.getWidth();
display.getHeight();
layoutInflaterClasses = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
然后点击你想要打开滑块的任何按钮或图片放在代码下面。
findViewById(R.id.slidermenu).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (!alreadyShowing) {
alreadyShowing = true;
openSlidingMenu();
}
}
});
然后在onCreate之外声明 openSlidingMenu(),如下所示。
private void openSlidingMenu() {
// showFadePopup();
int width = (int) (windowWidth * 0.8f);
translateView((float) (width));
@SuppressWarnings("deprecation")
int height = LayoutParams.FILL_PARENT;
// creating a popup
final View layout = layoutInflaterClasses.inflate(
R.layout.option_popup_layout,
(ViewGroup) findViewById(R.id.popup_element));
ImageView imageViewassignment = (ImageView) layout
.findViewById(R.id.assignment);
imageViewassignment.setOnClickListener(this);
final PopupWindow optionsPopup = new PopupWindow(layout, width, height,
true);
optionsPopup.setBackgroundDrawable(new PaintDrawable());
optionsPopup.showAtLocation(layout, Gravity.NO_GRAVITY, 0, 0);
optionsPopup.setOnDismissListener(new PopupWindow.OnDismissListener() {
public void onDismiss() {
// to clear the previous animation transition in
cleanUp();
// move the view out
translateView(0);
// to clear the latest animation transition out
cleanUp();
// resetting the variable
alreadyShowing = false;
}
});
}
只需替换
final View layout = layoutInflaterClasses.inflate(
R.layout.option_popup_layout,
(ViewGroup) findViewById(R.id.popup_element));
以上代码包含您的自定义屏幕XML名称及其ID。这是你需要的其他方法。
private void translateView(float right) {
animationClasses = new TranslateAnimation(0f, right, 0f, 0f);
animationClasses.setDuration(100);
animationClasses.setFillEnabled(true);
animationClasses.setFillAfter(true);
classesSlider = (RelativeLayout) findViewById(R.id.classes_slider);
classesSlider.startAnimation(animationClasses);
classesSlider.setVisibility(View.VISIBLE);
}
private void cleanUp() {
if (null != classesSlider) {
classesSlider.clearAnimation();
classesSlider = null;
}
if (null != animationClasses) {
animationClasses.cancel();
animationClasses = null;
}
}
记住这里animationClasses = new TranslateAnimation(0f, right, 0f, 0f);
您可以使用此参数进行一些不同的效果,也不要忘记使用当前屏幕的ID更改此行的ID,例如检查以下ID
classesSlider = (RelativeLayout) findViewById(R.id.classes_slider);
在这里,您需要将此ID替换为当前java屏幕的XML文件ID。
希望这会对你有所帮助。