Android: layout_alignParentBottom by code

How to set android:layout_alignParentBottom="true" for video review, by code, and not from xml?

+4
source share
4 answers

I assume you are trying to add a 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); 
+17
source
 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); 
+3
source

get layout options from your view and add a rule

  RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) view.getLayoutParams(); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); 
+2
source

Some links here1 and here2

this is what you need to do:

Create a RelativeLayout.LayoutParams object. To add rules, use addRule (int) or addRule (int, int). The first method is used to add rules that do not require values. Set the parameters for the presentation (in this case, for 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); 
0
source

Source: https://habr.com/ru/post/1384856/


All Articles