Get Android notification panel width
Asked Answered
C

2

12

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.

Carnage answered 20/7, 2016 at 18:23 Comment(6)
I am not aware of any API that offers this, and I would be skeptical about any hacks. For example, notifications on Chrome OS (raised by Android apps) go in the Chrome OS notifications area, which is somewhat different than the notification shade on ordinary Android environments.Granny
i have the same problemSouza
maybe you can share your code for this?Grecize
Please refer this link, #21237995Ramsey
The smallest android phone screen today is 360dp wide and the notification shade is 400dp wide on tablets. Why don't you just build one layout and rely on having just 360dp of available space?Madi
so have u solved this problem and how ?Perlite
F
2

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 :).

Fetial answered 28/10, 2016 at 16:16 Comment(5)
i need exact width of panel in pixels :)Souza
Why do you need exact width? It's never good idea to calculate size of views manually.Maddalena
i need it for calculating the size of bitmap in my image download task @VladimirSouza
You can use fitCenter or cropInside on your ImageView for scaleType, and use approximation for image size (size of notification panel shouldn't be bigger than 300dp)Maddalena
i know that , my problem is resizing large bitmaps that need exact size of the image view that is displaying that bitmap @VladimirSouza
H
0

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

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

Use the width to calculate your custom layout

Hindquarter answered 28/10, 2016 at 4:19 Comment(3)
I think, this code will provide maximum width and height of the screen available. Not Notification panel width.Rosamondrosamund
maybe this will answer your question.Hindquarter
This is definitely not the size of the notifications. It will give wrong dimension for tablets. And there is guarantee for the future for this to be true either.Meltage

© 2022 - 2024 — McMap. All rights reserved.