How to set android:layout_alignParentBottom="true"
for a videoview, by code and not from xml?
Asked
Active
Viewed 1.6k times
4 Answers
23
I assume you are trying to add your VideoView
to a RelativeLayout
?
RelativeLayout relativeLayout = findViewById(R.id.your_relative_layout);
mVideo = new VideoView(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); // or wrap_content
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
relativeLayout.addView(mVideo , layoutParams);

Ross Rogers
- 23,523
- 27
- 108
- 164

Reno
- 33,594
- 11
- 89
- 102
-
I don't think there is a `ALIGN_PARENT_BOTTOM` for `LinearLayout`, you have to use `android:gravity="bottom"` or [setGravity()](http://developer.android.com/reference/android/widget/LinearLayout.html#setGravity%28int%29) to bottom. – Reno Dec 06 '11 at 08:55
-
1I changed LinearLayout to RelativeLayout and it works ..thanks :) – Gabrielle Dec 06 '11 at 08:56
5
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
YourVideoView.setLayoutParams(params);

Rakhita
- 4,493
- 1
- 16
- 15
2
get layout params from your view and add rule
RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) view.getLayoutParams();
lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

Buda Gavril
- 21,409
- 40
- 127
- 196
0
Some References are Here1 and Here2
this is what you have to do:
Create a RelativeLayout.LayoutParams object. Use addRule(int) or addRule(int, int) to set the rules. The first method is used to add rules that don’t require values. Set the parameters to the view (in this case, to each button).
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT,RelativeLayout.TRUE);
yourView.setLayoutParams(params);
-
While this may answer the question, [it would be preferable](http://meta.stackexchange.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Taryn Mar 18 '13 at 11:48