Linearlayout Not Initialised In Onstart
Solution 1:
The Views are not measured at that point yet. But when you press the button, the View
In order to perform drawing when the View has just been measured from outside the View, you can set OnPreDrawListener or OnGlobalLayoutListener to View's ViewTreeObserver. Set this on onCreate() of the Activity.
ll_graph.getViewTreeObserver().addOnPreDrawListener(newViewTreeObserver.OnPreDrawListener() {
@OverridepublicbooleanonPreDraw() {
ll_graph.getViewTreeObserver().removeOnPreDrawListener(this);
//do your stuffreturntrue;
}
});
Solution 2:
The Activity will not necessarily be visible in the onCreate() and onStart() methods. Rather put your drawing code in onwindowFocusChanged(boolean), since the API doc states that "This is the best indicator of whether this activity is visible to the user."
Solution 3:
You can also post runnuble to a handler of your view. This runnable will execute, when your view is created.
@OverrideprotectedvoidonCreate(final Bundle b) {
super.onCreate(b);
ll_graph.post(newRunnable() {
@Overridepublicvoidrun() {
ll_graph.setBackgroundResiurce(resId);
}
});
}
Solution 4:
solution:-
Android lays the view in two phases : measure pass layout pass So This code waits for that phase and when layout has been laid out it will notify you the change.
ViewTreeObservervto= ll_graph.getViewTreeObserver();
vto.addOnGlobalLayoutListener(newOnGlobalLayoutListener() {
@OverridepublicvoidonGlobalLayout() {
ll_graph.getViewTreeObserver().removeGlobalOnLayoutListener(
this);
intll_width= ll_graph.getWidth();
intll_height= ll_graph.getHeight();
}
});
Post a Comment for "Linearlayout Not Initialised In Onstart"