How to get the visible size on an Activity?

android get screen size
android get current screen size
how to get mobile screen size in android
android get height of view programmatically
how to check screen size of mobile
android get width of the view
android get view height
get display resolution android

How can I know the visible size of my activity?

I'm trying to get the Activity real size, not the height and width from getHeight() and getWidth(), which gives me the screen full size.

I think you'll want to look at Activity.getWindow() and Window.getDecorView(), and get the width/height of that.

android - How to get the visible size on an Activity?, How can I know the visible size of my activity? I'm trying to get the Activity real size, not the height and width from getHeight() and getWidth() , which gives me the  Jun 17, 2010. How can I know the visible size of my activity? I'm trying to get the Activity real size, not the height and width from getHeight() and getWidth(),which gives me the screen full size.

I've found a way to know the exact height of my activity: if you have a view filling all the available screen behind the title bar and the task bar, just use View.getBottom() to get the real height of that activity.

Psychology and history of philosophy, We have as yet supposed visible movement and form in only two dimensions, are accompanied with a consciousness of activity, or the contraction of muscles. There are two ways to set and change visibility of linear layout. 1. Using XML 2. Using java class Using XML : use attribute android:visibility=”gone| visible|invisible” Using java class : use findViewById to get linear layout id like R.id.linearl

I like time-saving answers more:

myActivity.getWindow().getDecorView().getHeight();
myActivity.getWindow().getDecorView().getWidth();

Mental and Moral Science by Alexander Bain: Psychology and history , We have as yet supposed visible movement and form in only two dimensions, are accompanied with a consciousness of activity, or the contraction of muscles. Declares an activity (an Activity subclass) that implements part of the application's visual user interface. All activities must be represented by {@code } elements in the manifest file. Any that are not declared there will not be seen by the system…

I did that using my root layout, the problem is that you can't obtain this info (width and height) in your onCreate/onStart/onResume methods when they are running by the first time.

Any moment after that, the size can be retrieved from your root layout (LinearLayout/FrameLayout/TableLayout/etc), in my case I was using FrameLayout:

FrameLayout f = (FrameLayout) findViewById(R.id.layout_root);
Log.d(TAG, "width " + f.getMeasuredWidth() );
Log.d(TAG, "height " + f.getMeasuredHeight() );

or:

FrameLayout f = (FrameLayout) findViewById(R.id.layout_root);
Log.d(TAG, "width " + f.getRight() );
Log.d(TAG, "height " + f.getBottom() );

Edited from here --------------------------------------------------------

I found a way to get this info on the onCreted method, but only if your have more then one activity. On my case I have a main activity that calls second activity.

On main_activity before I call the second_activity, by a new Itent, I can add extra info for the second_activity. Here is the code you need on the first activity:

Intent i = new Intent(this, SecondActivity.class);
i.putExtra("width", f.getMeasuredWidth());
i.putExtra("height", f.getMeasuredHeight());
startActivity(i);

After that on your second activity you can retrieve this info on the onCreate method of your second activity doing that:

int width = getIntent().getExtras().getInt("width");
int height = getIntent().getExtras().getInt("height");

Mental science, We have as yet supposed visible movement and form in only two dimensions, are accompanied with a consciousness of activity, or the contraction of muscles. if you are in a activity, assume there is only one root view,you can get it like this. ViewGroup viewGroup = (ViewGroup) ( (ViewGroup) this .findViewById(android.R.id.content)).getChildAt(0); you can then cast it to your real class. or you could using. getWindow().getDecorView();

There is simple way to get right View size using getDefaultSize function. In case of View spanning on entire activity, you can use next approach to get activity client region dimensions:

public void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
    int viewWidth = getDefaultSize(getWidth(), widthMeasureSpec); 
    int viewHeight = getDefaultSize(getHeight(), heightMeasureSpec);
    ...
}

To make View extending on entire activity:

MyView testView = new MyView(this);
LinearLayout testViewGroup = new LinearLayout(this);
testView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                                          LayoutParams.FILL_PARENT);
testViewGroup.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
                                               LayoutParams.FILL_PARENT);
testViewGroup.addView(testView);
setContentView(testViewGroup);

Mental and Moral Science: A Compendium of Psychology and Ethics, We have as yet supposed visible movement and form in only two dimensions , or accompanied with a consciousness of activity , or the contraction of muscles . To navigate from one screen to another screen, use following code : Intent intent = new Intent(context, anotherActivity.class); startActivity(intent); File : AppActivity.java

Thermotropic Liquid Crystals: Recent Advances, explained assuming arbitrarily oriented sub-visible size birefringent domains optical activity, but as we have seen achiral bent-core liquid crystals can have  Get Visible Text extracts a string and its information from an indicated UI element using the Native screen scraping method. This activity can also be automatically generated when performing screen scraping, along with a container. This activity can be useful in retrieving text from desktop and web applications.

Visible-Light-Active Photocatalysis: Nanostructured Catalyst , Noble metal nanoparticles (and in particular plasmonic NPs) have been the high electromagnetic energy within their small particle size owing to the localized Ag, and photocatalysis to increase the photocatalytic activity [1, 11, 18–21]. @MuhammadBabar: You can try executePendingTransactions() on FragmentManager after calling commit() on the transaction, though I have not tried this. Or you can use setContentView() to use a layout file with a <fragment> tag.

Get actual screen size for the application layout dynamically , For that, we need to know the screen size programmatically before showing the Activity, i.e., in onCreate() method. Knowing screen size or  UiPath.Core.Activities.GetFullText Extracts a string and its information from an indicated UI element using the FullText screen scraping method. This activity can also be automatically generated when performing screen scraping, along with a container.

Comments
  • Why do you want to do that? In the most cases this is not necessary and the most things you could need it for can be done with better techniques that come with android to handle different screen sizes.
  • I really need to know how many pixels the activity has in its width and height. It has to do with cartographic precision.
  • Are you using a mapview or a custom view for displaying the map?
  • Yes, I am creating a map view from scratch for proprietary cartographic info. I've found that it's easier to implement it myself than to use code from others (at least for me :-)).
  • int height = this.getWindow().getDecorView().getHeight();
  • I still get 0, strange.
  • You are calling it too early it doesn't have a height during onCreate().
  • I think the best is to add a preDrawListener to the TreeObserver sceneView.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { sceneView.getViewTreeObserver().removeOnPreDrawListener(this); //do code here that has window)
  • getBottom() of what? What class has this method?
  • Any View : developer.android.com/reference/android/view/… it is relative to the parent which is why you need it to be a view that fills all the available screen in this case.
  • int height = this.getWindow().getDecorView().getBottom();
  • getWindow().getDecorView().getBottom() returns the height of the screen in pixels.