I'm developing a application where the user is supposed to be able to alter the apperence of a button by pressing other buttons. I use four buttons to set height as wrap content, height as fill parent, width as wrap content and width as fill parent.
I googled a bit and found a solution using LayoutParams although that code didn't specify if height of width was alterd. I also got errors saying my IDE couldn't recognise "LayoutParams". What is the best way to do this?
What you need to look for - is View.ViewGroup.LayoutParams. Every LayoutParams has constant value for MATCH_PARENT and WRAP_CONTENT attributes. I have prepared simple code sample you can play with:
Activity:
Layout xml:
By using the below code you can easily alter the height and width dynamically.