0
我有以下代碼在case1它使一個字段不可見和其餘字段填充屏幕但是我想恢復到原來的xml佈局一旦case2是在影響。恢復以編程方式更改佈局爲原始xml文件的設置
這是我的代碼;
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.item1:
singleView=true;
doubleView=false;
if(singleView && !doubleView){
webView2.setVisibility(View.INVISIBLE);
urlEditText2.setVisibility(View.INVISIBLE);
openUrl2.setVisibility(View.INVISIBLE);
webView.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
}
else{
}
//webView.setLayoutParams(new RelativeLayout.LayoutParams(10, 100));
return true;
case R.id.item2:
singleView = false;
doubleView = true;
webView2.setVisibility(View.VISIBLE);
urlEditText2.setVisibility(View.VISIBLE);
openUrl2.setVisibility(View.VISIBLE);
webView = (WebView) findViewById(R.id.webView);
urlEditText = (EditText) findViewById(R.id.urlField);
openUrl = findViewById(R.id.goButton);
Toast.makeText(this, "Option2", Toast.LENGTH_SHORT).show();
return true;