Niz*_*rif 6 android android-relativelayout exoplayer
在我的 Android 应用程序中。我已在详细信息活动中添加了 exoplayer,可以通过单击回收器视图列表项中的链接来访问它。现在的问题是在加载详细信息屏幕时。
Exoplayer 填满屏幕一会儿,然后布局开始填充。我希望在单击列表中的项目后将视频加载到布局屏幕中,而不需要全屏加载。请在下面找到有关相同内容的 gif。
详细信息屏幕的 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="match_parent"
android:orientation="vertical">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<com.google.android.exoplayer2.ui.SimpleExoPlayerView
android:id="@+id/exo_player_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/cardview_dark_background" />
<ImageView
android:id="@+id/exo_player_thumbnail_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
/>
<android.support.v4.widget.ContentLoadingProgressBar xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/exo_player_progress_bar"
style="?android:progressBarStyle"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:backgroundTint="@color/colorPrimary" />
</FrameLayout>
<TextView
android:id="@+id/recipe_short_desc_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:text="short description"
android:textSize="18dp"
android:textStyle="bold" />
<TextView
android:id="@+id/recipe_desc_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:padding="5dp"
android:text="description"
android:textSize="17dp" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
您需要手动设置 SimpleExoPlayerView 的尺寸,因为播放器在加载视频之前不知道视频的宽高比,这是异步的。
因此,在onCreate中,您需要使用findViewById(int id)查找SimpleExoPlayerView,并根据SimpleExolayerView的父视图的宽度和视频的长宽比设置LayoutProperies的高度。
| 归档时间: |
|
| 查看次数: |
2692 次 |
| 最近记录: |