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.

M. Reza Nasirloo
  • 16,434
  • 2
  • 29
  • 41
  • 1
    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. – CommonsWare Jul 20 '16 at 18:30
  • i have the same problem – Mohsen fallahi Oct 22 '16 at 13:23
  • maybe you can share your code for this? – Sodiq Oct 25 '16 at 02:38
  • Please refer this link, http://stackoverflow.com/questions/21237495/create-custom-big-notifications – Jayamurugan Oct 25 '16 at 04:28
  • The smallest *android* phone screen *today* is [360dp wide](https://design.google.com/devices/) and the notification shade is [400dp wide on tablets](https://cdn2.pcadvisor.co.uk/cmsdata/features/3586448/Android_Lollipop_notifications_bar.png). Why don't you just build one layout and rely on having just 360dp of available space? – Eugen Pechanec Oct 26 '16 at 02:05
  • 1
    so have u solved this problem and how ? – IloveIniesta Feb 24 '17 at 09:23

2 Answers2

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

Vladimir Jovanović
  • 2,261
  • 2
  • 24
  • 43
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

ZeroOne
  • 8,996
  • 4
  • 27
  • 45
  • 5
    I think, this code will provide maximum width and height of the screen available. Not Notification panel width. – Akshay Oct 28 '16 at 08:53
  • maybe [this](http://stackoverflow.com/questions/3355367/height-of-statusbar/3356263#3356263) will answer your question. – ZeroOne Oct 28 '16 at 09:09
  • 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. – tasomaniac Nov 24 '16 at 10:48