I get the root view (Which in my case happens to be RelativeLayout) using the below code:
final ViewGroup viewGroup = (ViewGroup) ((ViewGroup) this
.findViewById(android.R.id.content)).getChildAt(0);
Source: Get root view from current activity
Now I want to set the size and the layout gravity of the root view. But I don't know the layout type of its parent
The below code works when the view I want to set it's layout params is inside a LinearLayout.
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
params.weight = 1.0f;
params.gravity = Gravity.TOP;
button.setLayoutParams(params);