我想设置一个空白的relativeLayout,然后开始从另一个relativeLayout添加一些视图。Android:如何从不同的布局添加视图
我想这样做,因为此刻我在单个布局中有很多位图会导致内存错误。所以我想实现添加和删除视图的效果,因为我认为在代码中是合适的。
目前我在onCreate()
上使用setContentView()
布局,这使得我有内存错误,因为有太多的视图要一次添加。
另一种方式。也许这是可能setContentView()
的布局与太多的意见。只有在我编写代码以添加特定视图之前,才能添加任何视图。
setContentView(R.layout.start_up_screen_denmark);
// This will add all the views in the layout causing a memory error. Making everything below irrelavant.
// So perhaps there is a way to set the ContentView without adding all the views automaticly.
// Perhaps i can set a blank layout and add views to that layout from the other layout at will.
ImageView denmark = (ImageView) findViewById(R.id.GoDenmark);
ViewGroup parent = (ViewGroup) denmark.getParent();
parent.removeView(denmark);
在静态视图(如ImageView)中替换图像不是更容易吗? –
我在这里关于android的整个内存问题。但我读了几篇文章,如果你想避免内存泄漏,那么不要设置任何静态。 – Nulle