How to set android:layout_alignParentBottom="true"
for a videoview, by code and not from xml?
android:layout_above : Places the element above the specified element. android:layout_below : Places the element below the specified element. android:layout_toLeftOf : Places the element to the left of the specified element. android:layout_toRightOf : Places the element to the right of the specified element.
There are two main ways to programmatically set the gravity in a RelativeLayout . You can either set the gravity for all child views ( setGravity(int) ) or set the gravity individually ( params. addRule(int) ). Note: These methods are not available for LinearLayout s.
If you have a single Button in your Activity and you want to center it the simplest way is to use a RelativeLayout and set the android:layout_centerInParent=”true” property on the Button.
Some of the many layout properties available to views in a RelativeLayout include: android:layout_alignParentTop. If "true" , makes the top edge of this view match the top edge of the parent. android:layout_centerVertical.
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);
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