У меня есть приложение, которое показывает списки прямых трансляций. Я использую VideoView в RecyclerView, чтобы сделать это. Однако, кажется, что VideoView продолжает изменять размеры, которые, я думаю, основаны на контенте. Вот мой XML.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<VideoView
android:id="@+id/vv_monitor"
android:layout_width="match_parent"
android:layout_height="250dp"
android:layout_centerInParent="true" />
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="@dimen/text_view_margin"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/tv_watching"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@drawable/rounded_corner"
android:drawableStart="@drawable/ic_remove_red_eye_white_12dp"
android:drawablePadding="@dimen/text_view_margin"
android:paddingLeft="@dimen/text_view_margin"
android:paddingRight="@dimen/text_view_margin"
android:text="@string/app_name"
android:textColor="@android:color/white"
android:textSize="@dimen/small_text_size" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="@dimen/activity_horizontal_margin">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/app_name"
android:textSize="@dimen/small_text_size" />
<TextView
android:id="@+id/tv_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:textSize="@dimen/small_text_size" />
</LinearLayout>
<TextView
android:id="@+id/tv_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/small_text_size"
tools:text="asdasda | h264 | mp4" />
</LinearLayout>
</LinearLayout>
Вот где я вызываю VideoView в адаптере.
viewHolder.videoViewMonitor.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
mp.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
}
});
viewHolder.videoViewMonitor.setVideoURI(Uri.parse(monitor.getUrl()));
viewHolder.videoViewMonitor.start();
Как показано в коде выше, я установил высоту для моего VideoView на 250dp. Первоначально, когда показывает Activity, высоты VideoViews в RecyclerView все равны. Но когда содержимое начинает загружаться, VideoView изменяет размер, а высота уменьшается в размере.
Вызов mp.setVideoScalingMode(MediaPlayer.VIDEO_SCALING_MODE_SCALE_TO_FIT_WITH_CROPPING);
, похоже, ничего не делает.
Ценю любые отзывы.