Adjust width to half screen

前端 未结 5 1995
再見小時候
再見小時候 2021-01-05 05:27

I came across this link :

Assign width to half available screen width declaratively

How to do the same in relative layout? Here\'s the code: Trying linea

5条回答
  •  天命终不由人
    2021-01-05 06:11

        Display display = getWindowManager().getDefaultDisplay();
        int width = display.getWidth();
        int height = display.getHeight();
        plannerEditLayout = (RelativeLayout) findViewById(R.id.plannerLayoutEdit);
        plannerEditLayout.setGravity(Gravity.CENTER_VERTICAL);
        plannerEditLayout.setLayoutParams(new RelativeLayout.LayoutParams(
                (width / 2), height));
    

    I use the same code for LinearLayout. Havent tried it out myslef for RelativeLayout. Give it a shot. Comment if it doesn't work.

提交回复
热议问题