Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set LayoutParams to fragment by programming

How can I set LayoutParams to Fragment programmatically?

Actually : I wanna add two Fragments to a LinearLayout programmatically and I need set android:layout_weight for them. I am newbie in Fragment. I don't know whether it is a good way or not to add two Fragments to a Layout

Sorry. My English is not really well.

like image 388
kdtphdav Avatar asked Sep 01 '12 02:09

kdtphdav


People also ask

How can set activity to fragment?

Add a fragment to an activity You can add your fragment to the activity's view hierarchy either by defining the fragment in your activity's layout file or by defining a fragment container in your activity's layout file and then programmatically adding the fragment from within your activity.

What method of the FragmentTransaction class is used to add a fragment to an activity?

It is the add() method on the FragmentTransaction which adds the fragment to the activity. The add() method takes two parameters. The first parameter is the id of the parent ViewGroup into which the fragment's View is to be inserted. The second parameter is an instance of the fragment to add.

How do I load a fragment?

To load a fragment in an activity at first we need to have an activity and xml file which should have a parent layout that may hold the fragment when it is loaded in that layout. For loading a fragment we need to do a fragment transaction that load the fragment in stack.

What is child view in android?

In android (and most other technologies), views can have subviews, aka "children". Most views can have children and can be a child of a parent view. It's kind of like a "tree". The most obvious feature of being a child of some other view is that the child moves with the parent view.


1 Answers

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT);
params.weight = 3.0f;
fragment.getView().setLayoutParams(params);
like image 118
user457015 Avatar answered Oct 05 '22 23:10

user457015