Get height and width of a layout programmatically

前端 未结 16 1466
别那么骄傲
别那么骄傲 2020-11-27 13:55

I have designed an layout in which LinearLayout has 2 children LinearLayout and FrameLayout and in each child I put different views.

16条回答
  •  旧时难觅i
    2020-11-27 14:54

    I used DisplayMetrics to get the screen size and then i can assign the width/height to an element in %age

    It will be like this

    DisplayMetrics dmetrics = new DisplayMetrics();
    int widthPixels=dmetrics.widthPixels;
    int heightPixels=dmetrics.heightPixels;       
    
    //setting the height of the button 
    button_nextPuzzle.setMinHeight((int) ((heightPixels/3)*.30));
    

    Worked for me very well!!!

提交回复
热议问题