3
我想要一個TextView
頂部和它下面的VideoView
。我想要VideoView
作爲中心verical和低於TextView
。我正在使用RelativeLayout
。Android - 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
沒有垂直居中。
我對videoview使用fill_parent/fill_parent的原因是我希望視頻能夠填充TextView下面的所有空間。視頻只能根據其縱橫比允許的比例進行擴展,這就是爲什麼需要進行對中,尤其是在縱向模式下。 – Chris 2010-07-25 00:18:18