android:layout_alignParentBottom代码

时间:2011-12-06 08:39:15

标签: android alignment

如何通过代码而非xml为视频视图设置android:layout_alignParentBottom="true"

4 个答案:

答案 0 :(得分:20)

我假设您要将VideoView添加到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);

答案 1 :(得分:3)

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);

答案 2 :(得分:2)

从您的视图中获取布局参数并添加规则

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

答案 3 :(得分:0)

有些参考文献是Here1Here2

这就是你要做的事情:

创建RelativeLayout.LayoutParams对象。 使用addRule(int)或addRule(int,int)来设置规则。第一种方法用于添加不需要值的规则。 将参数设置为视图(在本例中为每个按钮)。

    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);