我需要创建一个视频视图,在运行时,它应该位于id为 "video1 "的视频视图下面。下面是代码。
RelativeLayout layout = findViewById(R.id.layout);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams)
layout.getLayoutParams();
params.addRule(RelativeLayout.BELOW, R.id.video1);
videoView2 = new VideoView(jazz.this);
videoView2.setLayoutParams(params);
videoView2.setLayoutParams(new
FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 200));
layout.addView(videoView2);
这是你的代码。
videoView2.setLayoutParams(params);
videoView2.setLayoutParams(new
FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, 200))
你设置了两次LayoutParams...
用这个。
VideoView v = new VideoView(context);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, 200);
layoutParams.addRule(RelativeLayout.BELOW, R.id.video1);
v.setLayoutParams(layoutParams);
container.addView(v);
这样就可以了,希望有人能帮你
你应该像这样为你的video2设置参数。
RelativeLayout layout = (RelativeLayout)findViewById(R.id.layout);
videoView2 = new VideoView(this);
videoView2.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,200));
layout.addView(videoView2);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) videoView2.getLayoutParams();
params.addRule(RelativeLayout.BELOW, R.id.video1);
videoView2.setLayoutParams(params);
而你的video1应该有一个高度参数设置,因为videoview的测量是基于你设置的视频,从外观上看,没有定义视频路径,所以如果video1高度=wrap_content,它需要整个屏幕,没有任何约束。我有我的在xml这样的。
<VideoView
android:id="@+id/video1"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginBottom="20dp"/>