问题描述
我想迫使主体布局,资源视图重绘/刷新,在说Activity.onResume()方法。我怎样才能做到这一点?
通过主要的布局来看,我所指的是('R.layout.mainscreen下面)被称为在我Activity.onCreate(),像这样: -
保护无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.mainscreen);
}
任何帮助,很多AP preciated,米
要严格回答这个问题:使用无效():
的ViewGroup VG = findViewById(R.id.mainLayout);
vg.invalidate();
现在,该活动恢复时,它使每个View绘制自己。应该不需要调用无效()。要应用的主题,确保你做的任何视图绘制之前,即前的setContentView(R.layout.mainscreen);
该API文档参考这里:http://developer.android.com/reference/android/view/ContextThemeWrapper.html#setTheme%28int%29
由于的OnDraw()方法适用于已经实例化的意见,setTheme将无法正常工作。我有自己的主题没有任何经验,但有两个备选方案我能想到的是:
- 在调用setTheme中的onCreate()来替代,或者
- 重做的setContentView(R.layout.mainscreen);强制所有重新实例布局。
I want to force the main layout resource view to redraw / refresh, in say the Activity.onResume() method. How can I do this ?
By main layout view, I mean the one ('R.layout.mainscreen' below) that is called in my Activity.onCreate(), like this:-
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mainscreen);
}
Any help, much appreciated,M.
To strictly answer the question: Use invalidate():
ViewGroup vg = findViewById (R.id.mainLayout);
vg.invalidate();
Now, when the Activity resumes, it makes every View to draw itself. No call to invalidate() should be needed. To apply the theme, make sure you do it before any View is drawn, i.e., before setContentView(R.layout.mainscreen);
The API doc reference is here: http://developer.android.com/reference/android/view/ContextThemeWrapper.html#setTheme%28int%29
Since the onDraw() method works on already instantiated Views, setTheme will not work. I have no experience with themes myself, but two alternative options I can think are:
- call setTheme in onCreate() instead, or
- redo setContentView (R.layout.mainscreen); to force reinstantiate all the layout.
这篇关于如何迫使整个布局视图刷新?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!