我正在开发一个Android应用程序,我使用LayoutInflator
来生成新布局。该应用程序的基本功能是 - 它具有一个imageview。当我点击一个按钮时,我将布局更改为显示多个ImageView(如2x2或4x4)。我成功地使用LayoutInflator显示这些布局。但是,之前的布局保持不变,新布局显示而不是旧布局,这种布局会混淆整个布局。我的问题是 - 无论如何要在显示新的布局之前销毁旧的布局?如何销毁布局?
编辑:
这里是代码(在onClick事件,我使用)
public void oneby1onClick(View view){
RelativeLayout main = (RelativeLayout)findViewById(R.id.main_layout);
view = getLayoutInflater().inflate(R.layout.activity_main, main,false);
main.removeView(main);
main.addView(view);
}
public void twoby2onClick(View view){
RelativeLayout main = (RelativeLayout)findViewById(R.id.main_layout);
view = getLayoutInflater().inflate(R.layout.twoby2, main,false);
main.removeView(main);
main.addView(view);
}
public void fourby4onClick(View view){
RelativeLayout main = (RelativeLayout)findViewById(R.id.main_layout);
view = getLayoutInflater().inflate(R.layout.fourby4, main,false);
main.removeView(main);
main.addView(view);
}
后您的应用程序的代码。 – Egor
您不会销毁布局,而是替换它。看起来你做错了,因为通常布局不会出现在彼此之上,除非你真的把它添加在顶部。 – zapl
^+ 1我这样做,只是我有布局上的onclick事件改变像[这个链接提示](http://myandroidsolutions.blogspot.com/2012/06/android-layoutinflater-turorial.html)的按钮。 @zapl - 你如何替换布局? – TheRookierLearner