Can I find out the width of screen programmatically in android app? I need to paint canvas but its width should be almost like screen and I could not set match_parent in java part program.
            Asked
            
        
        
            Active
            
        
            Viewed 8,476 times
        
    3 Answers
10
            You can get default Display instance and then read width/height from it:
int width = getWindowManager().getDefaultDisplay().getWidth();
int height = getWindowManager().getDefaultDisplay().getHeight();
 
    
    
        inazaruk
        
- 74,247
- 24
- 188
- 156
- 
                    2This method is deprecated. – princepiero Sep 17 '13 at 11:14
2
            
            
        You could also overwrite onSizeChanged(int,int,int,int) in any view and set it in there.
 
    
    
        SBoss
        
- 8,845
- 7
- 28
- 44
 
     
     
    