There is a 20dp button for 20dp , after pressing the button, the background changes in the button, and the button size should change ( 50dp to 50dp ). How to implement it correctly? Button sizes are given in xml ( 20dp to 20dp ). I tried to do mButton.setHeight(), mButton.setWidth() after clicking on the button, but this method does not work. Or just need to hide one button? And display another?

How to do it right?

    1 answer 1

     ViewGroup.LayoutParams params = button.getLayoutParams(); int sizeInPX= (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 50, getResources().getDisplayMetrics()); params.height = sizeInPX; params.width = sizeInPX; button.setLayoutParams(params); 
    • PS: the setHeight (), setWidth () methods exist. - Lucky_girl
    • @Lucky_girl; Exactly, TextView has them, and I watched the Button sources. - Vladyslav Matviienko