Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android notification width

I am writing an application that builds a notification from several "symbols". Sometimes these won't fit and I'll just stop and add a number of symbols that did not fit.

Currently I'm looking at device's screen width to determine the number of symbols that do fit. Like this:

DisplayMetrics dm = resources.getDisplayMetrics();
int num = dm.widthPixels / height;

where height is "hardcoded" value of 64dp.

This does not work on tablets though. As result I'm losing rightmost symbols. Is there any way to determine the actual amount of space in my notification?

On this picture I'm using another hardcoded value of no more than 7 symbols total. enter image description here

like image 213
aragaer Avatar asked Nov 01 '12 20:11

aragaer


2 Answers

Are using height=64 or the equivalent of 64dp in pixels?

Why not get the width and height of your top layer to get the usable screen size instead of full screen size (including system and ActionBars)?

like image 185
rgrocha Avatar answered Oct 14 '22 16:10

rgrocha


Here's the answer I've been waiting for: 478dp

Source

Which results in about 7.5 symbols per notification and having a value of 7 hardcoded is correct.

like image 20
aragaer Avatar answered Oct 14 '22 14:10

aragaer