Is it possible to change the layout width and height in Android at run time?

后端 未结 5 1849
不思量自难忘°
不思量自难忘° 2021-01-01 16:22

I have two relative layouts. Both have width of fill parent and height of 100 dip. My requirement is when I click the first layout it should shrink to 50dip height and the o

5条回答
  •  猫巷女王i
    2021-01-01 17:13

    In onClick Listener add this code.

    Button button = (Button) findViewById(view.getId());
    LinearLayout rLGreen = ((LinearLayout) button.getParent());
    rLGreen.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    

    It will work.

提交回复
热议问题