Set fragments parameters programatically in android

android, android-fragments, compatibility

Solution

How to set parameters like height, width ,margins for fragments programatically

Fragments do not have "parameters like height, width ,margins". `View` and `ViewGroup` have "parameters like height, width ,margins". So, you either adjust the container into which you are placing the fragment (which, for some strange reason, you have declared as `1` in your examples above), or you adjust the `View` that your `Fragment` returns from `onCreateView()`.

Problem

How to set parameters like height, width ,margins for fragments programatically. I am adding fragments like ``` FragmentManager fragmentManager = getSupportFragmentManager(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); MyListFragment myListFragment = new MyListFragment(); fragmentTransaction.add(1, myListFragment); DetailFragment detailFragment = new DetailFragment(); fragmentTransaction.add(1, detailFragment); fragmentTransaction.commit(); ``` Also I am using compatabilty jar like android-support-v4.jar. Thanks.

Original source