You can either create a new GridView.LayoutParams object and then pass it to setLayoutParams(...) or use the methods associated with the XML attributes to set each individual layout parameter from Java.
Just create
GridView.LayoutParams myParams = new GridView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
Then you can use the methods provided by GridView.LayoutParams through myParams.someMethodName(...) . You will find methods and supported parameters in the link above.
You will then pass the LayoutParams object to your view through myGridView.setLayoutParams(myParams);
source share