I am using below steps to know the width and height of contentview on my display screen
ContentViewWidth = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getWidth();
ContentViewHeight = getWindow().findViewById(Window.ID_ANDROID_CONTENT).getHeight();
but this method doesn't work inside onCreate or onResume and if I am using these steps inside onWindowFocusChanged I get force close error on my phone
Please help me how can I get the content view of my display screen. Content view is excluding statusbar and titlebar dimensions
I use the following technique - post a runnable from onCreate() that will be executed when the view has been created:
contentView = findViewById(android.R.id.content);
contentView.post(new Runnable()
{
public void run()
{
contentHeight = contentView.getHeight();
}
});
This code will run on the main UI thread, after onCreate() has finished.
If you are trying to get the height of the content view itself, you need to subtract the padding from the height - this is because Android 2.x lays out the views differently to 4.x.
contentHeight = contentView.getHeight() - contentView.getTopPadding();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With