我正在尝试在屏幕上上下移动工具栏的简单任务,但它只能工作一次。工具栏在按下按钮时移动到顶部,但即使出现“移至底部”消息,我也无法将其移回底部。见代码:
boolean toolBarAtBottom = true;
private void moveToolBar(){
LinearLayout toolBar = (LinearLayout) findViewById(R.id.toolBar);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
lp.height = toolBar.getHeight();
if (toolBarAtBottom){
lp.addRule(RelativeLayout.ALIGN_TOP, RelativeLayout.TRUE);
}else{
lp.addRule(RelativeLayout.ALIGN_BOTTOM, RelativeLayout.TRUE);
Toast.makeText(DrawActivity.this, "move to bottom", Toast.LENGTH_SHORT).show();
}
toolBar.setLayoutParams(lp);
toolBarAtBottom = !toolBarAtBottom;
}
任何想法如何让它做不止一次?