我正在尝试像 facebook android 应用程序一样实现滑块菜单。
我已成功滑动菜单并将其重新滑回。
我有两个适合框架布局的视图。
1. 主布局 (X)
2. 菜单布局。(Y)
我将 X 向右滑动,在滑动时显示 Y,在向后滑动时,我将 X 移回 0,隐藏菜单。
@Override
public void setContentView(int layout) {
FrameLayout frame = new FrameLayout(getBaseContext());
frame.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT));
LayoutInflater inflator = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mainLayout = inflator.inflate(layout, null);
menuList = inflator.inflate(R.layout.menu_page, null);
fakeView= inflator.inflate(R.layout.fake_transparent_view, null);
menuAnimator = new MenuAnimation(mainLayout,menuList,fakeView);
frame.addView(menuList);
frame.addView(mainLayout);
frame.addView(fakeView);
fakeView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(mainLayout.getLeft()>0)
{
menuAnimator.moveMenu("left");
}
}
});
super.setContentView(frame);
}
public void moveMenu(String direction) {
int width=(int) (QuikrApplication.getWidth()*.85);
if (direction.equals("right")) {
this.direction="right";
fakeView.setVisibility(View.VISIBLE);
TranslateAnimation moveRight = new TranslateAnimation(0, width, 0, 0);
moveRight.setDuration(500);
parentLayout.setAnimation(moveRight);
moveRight.setAnimationListener(animationListner);
parentLayout.startAnimation(moveRight);
fakeView.startAnimation(moveRight);
}
else if (direction.equals("left")){
this.direction="left";
TranslateAnimation moveLeft = new TranslateAnimation(0, -width, 0, 0);
moveLeft.setDuration(500);
parentLayout.setAnimation(moveLeft);
moveLeft.setAnimationListener(animationListner);
parentLayout.startAnimation(moveLeft);
fakeView.startAnimation(moveLeft);
}
}
现在的问题是当我在主视图中异步执行一些操作时,主视图是重新定位(当菜单可见时)