Is it possible to add dynamically add Fragments with LayoutParams? I have 2 fragments that I want to put in a RelativeLayout: one should lock to the left. The other should be locked to the right.
I used the following approach for a ListFragment in a LinearLayout:
class CustomListFragment
extends ListFragment
{
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState)
{
ViewGroup v = (ViewGroup) super.onCreateView(inflater, container,
savedInstanceState);
v.setLayoutParams(new LinearLayout.LayoutParams(0,
LinearLayout.LayoutParams.MATCH_PARENT, 1));
return v;
}
}
Now that I read your comments on the other answer, I see it is similar to what you considered.
But note: the framework may instantiate your fragments. Therefore, the class must be public and must have a constructor without any further arguments.
Any setter-methods to customize your fragments won't work therefore, as they won't be called for any framework-created instances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With