我在我的应用程序的弹出页面中有视频查看,问题是媒体控制器位置不正常如下,我希望媒体控制器位于视频视图中,我该如何解决?
这是我显示视频视图和媒体控制器的代码,我已经将锚视图设置为视频视图,但它不起作用
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_popup_preview);
DisplayMetrics dm = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(dm);
int width = dm.widthPixels;
int height = dm.heightPixels;
getWindow().setLayout((int) (width * .9d), (int) (height * .65d));
final LatestVideo vid = getIntent().getParcelableExtra("videolatest");
String url_video = vid.source_content;
nama.setText(vid.name);
judul.setText(vid.judul);
harga.setText("Rp." + vid.price);
mediaController = new MediaController(this);
mediaController.setAnchorView(videoView);
Uri uri = Uri.parse(url_video);
videoView.setVideoURI(uri);
videoView.setMediaController(mediaController);
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mediaPlayer) {
videoView.start();
}
});
videoView.setOnErrorListener(new MediaPlayer.OnErrorListener() {
@Override
public boolean onError(MediaPlayer mediaPlayer, int i, int i1) {
return false;
}
});
loadRelatedLatestVideo();
}
这是弹出页面的布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:alpha="0.8"
android:gravity="center_horizontal"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="250dp"
android:orientation="vertical">
<FrameLayout
android:id="@+id/iv_video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="0dp"
android:layout_marginStart="0dp"
android:background="@android:color/black">
<FrameLayout
android:id="@+id/frm_controller"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" />
<VideoView
android:id="@+id/vv_RelatedLatestpreview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center" />
</FrameLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey_e4e4e4"
android:elevation="2dp"
android:orientation="vertical"
android:paddingLeft="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txtpopupnama"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Artis"
android:textSize="18sp" />
<TextView
android:id="@+id/txtpopupjudul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Judul Video"
android:textSize="16sp" />
<TextView
android:id="@+id/txtpopupharga"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginTop="3dp"
android:text="Harga"
android:textColor="@android:color/holo_blue_dark"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Berlangganan"
android:textAllCaps="false"
android:textSize="18sp"
android:id="@+id/btnSubscribe"
android:layout_margin="5dp"
android:textColor="@color/white"
android:background="@drawable/selector_rounded_blue_logo" />
答案 0 :(得分:0)
在setOnPreparedListener内部使用<div class="blur">
<img src="https://thecentraltrend.com/wp-content/uploads/2017/02/tunnel.jpg" />
</div>
mediaController.setAnchorView(videoView);
答案 1 :(得分:0)
尝试将视频控制器的parent(linearlayout)替换为relativelayout并设置属性
android:layout_alignParentBottom="true"
child(videocontroler)的在xml中为true。