Home » Android » Get Android notification panel width

Get Android notification panel width

Posted by: admin May 14, 2020 Leave a comment


I’m creating some custom remoteViews, In order to draw custom views and layouts to a bitmap as wide as the notification panel I need its exact width.

As every vendor changes the width of the notification panel and in most cases it will changes based on orientation, It’s difficult to find a regular pattern on that.

Is there any way to get its width?

enter image description here
enter image description here

The pink part is pure remoteViews and the bottom part is an imageview which I draw my custom view to it, since I don’t have the parent width, all the child views get crumble together.

How to&Answers:

The easiest way is to use LinearLayout with android:orientation="horizontal" and android:layout_width="match_parent", and to put android:layout_weight="1" and android:layout_width="0dp" for every view in that layout. That means that every view in that layout will have same width. More about it you can read here.

UPDATE: In here it says that notification tray width is 478dp.
So, try with that. Maybe some manufactures have different size, but this is good number to start with :).


You can try this to get the width and calculate your custom layout

DisplayMetrics displaymetrics = new DisplayMetrics();
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;

Use the width to calculate your custom layout