Android: How to Programmatically set the size of a Layout

前端 未结 4 548
南方客
南方客 2020-11-28 01:09

As part of an Android App I am building a button set. The buttons are part of a nested set of LinearLayouts. Using weight I have the set resizing itself automatically based

4条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 02:00

    LinearLayout YOUR_LinearLayout =(LinearLayout)findViewById(R.id.YOUR_LinearLayout)
        LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
                           /*width*/ ViewGroup.LayoutParams.MATCH_PARENT,
                   /*height*/ 100,
                   /*weight*/ 1.0f
                    );
                    YOUR_LinearLayout.setLayoutParams(param);
    

提交回复
热议问题