How can you tell when a layout has been drawn?
You can add a tree observer to the layout. This should return the correct width and height. onCreate()
is called before the layout of the child views are done. So the width and height is not calculated yet. To get the height and width, put this on the onCreate()
method:
final LinearLayout layout = (LinearLayout) findViewById(R.id.YOUR_VIEW_ID);
ViewTreeObserver vto = layout.getViewTreeObserver();
vto.addOnGlobalLayoutListener (new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
layout.getViewTreeObserver()
.removeOnGlobalLayoutListener(this);
} else {
layout.getViewTreeObserver()
.removeGlobalOnLayoutListener(this);
}
int width = layout.getMeasuredWidth();
int height = layout.getMeasuredHeight();
}
});
How do I know if a view has been drawn
since getVisibility() returns a predefined property and u don't want to set a listener; i think the only option is View.isShown().
i hope this helps.
How do i know, when view is drawn?
Try this method..It works fine for me.
ViewTreeObserver vto = YourView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//do your stuff here
}
});
How do i know, when view is drawn?
Try this method..It works fine for me.
ViewTreeObserver vto = YourView.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
//do your stuff here
}
});
How do I know if a view has been drawn
since getVisibility() returns a predefined property and u don't want to set a listener; i think the only option is View.isShown().
i hope this helps.
Detect when the application is completely drawn and visible
You are going to wrong direction I think.
you should try .post(Runnable action)
.
suppose linearLayout1 should be drawing at last, then you should try this...
linearLayout1.post(new Runnable() {
@Override
public void run() {// will be call when linearLayout1 will be completely loaded
// TODO Auto-generated method stub
//you can write your code here
}
});
Do something after activity's layout has been measured but not drawn on screen
You can use View.getViewTreeObserver()
for that purpose. It lets you be notified when a layout has just happened or when a draw is about to occur.
How can I tell when a Layout (and all its child Views) has fully finished inflating?
You can override onFinishInflate() in your custom layout. This is called as the last phase of inflation, after all child views have been added.
Related Topics
How to Get HTML Content from a Webview
Android Min Sdk Version Vs. Target Sdk Version
How to Make a Custom Keyboard in Android
How to Programmatically Set Style Attribute in a View
How to Set the Text Color of Textview in Code
Integrating the Zxing Library Directly into My Android Application
How to Put Google Maps V2 on a Fragment Using Viewpager
How to Completely Uninstall Android Studio from Windows(V10)
Determine If Running on a Rooted Device
How to Pause/Sleep Thread or Process in Android
Sending Images Using Http Post
Getting Exception "Illegalstateexception: Can Not Perform This Action After Onsaveinstancestate"
Drawing a Line/Path on Google Maps
How to Change the Status Bar Color in Android
Android Gradle Plugin 0.7.0: "Duplicate Files During Packaging of Apk"
How to Execute Dex: Multiple Dex Files Define Lcom/Myapp/R$Array;