2010-07-24 114 views
3

我想要一个TextView顶部和它下面的VideoView。我想要VideoView作为中心verical和低于TextView。我正在使用RelativeLayoutAndroid - RelativeLayout CENTER_VERTICAL和BELOW问题

我试图做到这一点代码:

RelativeLayout layout = new RelativeLayout(this); 
TextView tv = new TextView(this); 
tv.setText("Hello"); 
tv.setGravity(Gravity.RIGHT); 
tv.setTextColor(Color.WHITE); 
tv.setId(1); 

RelativeLayout.LayoutParams one = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 

one.addRule(RelativeLayout.ALIGN_PARENT_TOP); 
one.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); 


RelativeLayout.LayoutParams two = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT); 
two.addRule(RelativeLayout.CENTER_VERTICAL); 
two.addRule(RelativeLayout.BELOW, 1); 

VideoView mVideoView = new VideoView(this); 

layout.addView(tv, one); 
layout.addView(mVideoView, two); 

setContentView(layout); 

VideoView被放置在TextView下方,但VideoView没有垂直居中。

回答

1

您制作了您的VideoView fill_parent/fill_parent,这使其具有与其父亲RelativeLayout相同的尺寸。如果它与RelativeLayout一样大,则居中不能真正起作用。此外,您不能让VideoView既不在TextView下面,也不在父视图中垂直居中;它是一个或另一个。相反,您可以将ViewView居中并将TextView放在它上面。

+0

我对videoview使用fill_parent/fill_parent的原因是我希望视频能够填充TextView下面的所有空间。视频只能根据其纵横比允许的比例进行扩展,这就是为什么需要进行对中,尤其是在纵向模式下。 – Chris 2010-07-25 00:18:18