首页 > 解决方案 > 如何在 android 中设置 SimpleExoPlayerView 的最大高度?

问题描述

我正在使用Toro Player(包括 SimpleExoPlayerView)制作一个类似于 Facebook 提要页面的屏幕,我们可以在回收站视图中滚动并自动播放可见视频。我必须根据视频的纵横比设置视频播放器的高度,这是通过使用app:resize_mode="zoom"来实现的。但是有些视频(特别是屏幕录制的)的高度太长,整个手机屏幕都无法覆盖它们。现在我必须为这个视频播放器设置一个最大高度,这样任何视频的高度都只能在用户可见的移动屏幕上进行扩展。这是我的尝试:

这是我的回收站视图的项目布局:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintHeight_max="200dp"
app:layout_constrainedHeight="true"
xmlns:android="http://schemas.android.com/apk/res/android" >

<androidx.cardview.widget.CardView
    android:id="@+id/card"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="@color/cardview_light_background"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:background="@color/teal_700">

        <TextView
            android:id="@+id/tvTitle"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/white"
            android:padding="10dp"
            android:text="Title" />

        <com.google.android.exoplayer2.ui.SimpleExoPlayerView
            android:id="@+id/player"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/tvTitle"
            android:minHeight="200dp"
            app:resize_mode="zoom"
            app:surface_type="texture_view"
            app:use_controller="true" />

    </RelativeLayout>

</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

我尝试过设置最大高度,但总是重复同样的问题。任何建议都会很有帮助。

标签: android-recyclerviewandroid-videoviewexoplayerautoplay

解决方案


推荐阅读