如何解决具有零高度宽度的视频视图
我有一个带有布局的 videoView -
<LinearLayout
android:id="@+id/linear_one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_below="@id/linearlayout1">
<VideoView
android:id="@+id/video"
android:adjustViewBounds="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
/>
</LinearLayout>
现在使用 ImageView 这通常会填满整个屏幕宽度。 但是对于 VideoView,它的高度和宽度为零。
我特别提到了 LinearLayout 中的一个值,例如 500dp
android:layout_height="500dp"
然后以编程方式更改视频尺寸的高度 -
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
if(linearLayout.getTag() ==null || !linearLayout.getTag().toString().equals("Done")) {
try {
float mul = (float) 1000 / mp.getVideoWidth();
linearLayout.setLayoutParams(new RelativeLayout.LayoutParams(1000,(int) (mp.getVideoHeight() * mul)));
linearLayout.setTag("Done");
} catch (Exception e) {
Log.d("ListView1","Videoview layout exception: " + e.toString());
}
}
});
我想使用这个解决方案 - https://stackoverflow.com/a/31733959/245858
但不幸的是它不会奏效,因为我的观点是在回收者的观点下。
有什么方法可以解决这个问题。我的整个布局就像 -
<?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"
android:id="@+id/linearlayout"
>
<androidx.cardview.widget.CardView
android:id="@+id/cardview_two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:elevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/linearlayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TextView
android:id="@+id/text_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="15dp"
android:text="this is cool test this is cool test"
/>
</LinearLayout>
<RelativeLayout
android:id="@+id/linear_one"
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_below="@id/linearlayout1"
android:background="#000000">
<VideoView
android:id="@+id/video"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:focusable="false"
android:focusableInTouchMode="false"
/>
</RelativeLayout>
<LinearLayout
android:id="@+id/linear_time"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="@id/linear_one">
<TextView
android:id="@+id/text_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
android:textSize="10dp"
android:text="06-June-2021 14:22"
/>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>
<Space
android:layout_width="match_parent"
android:layout_height="10dp"/>
</LinearLayout>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。