0

I'm having a videoView with the layout -

<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>

Now with an ImageView this usually fills the entire the width of the screen. But with VideoView it's having a zero height and width.

I have specifically mention a value in the LinearLayout like 500dp

android:layout_height="500dp"

and then programatically change the height with the video dimensions -

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());
}
}
});

I wanted to use this solution - https://stackoverflow.com/a/31733959/245858

but unfortunately it wouldn't work out because my view is under a recycler view.

Is there any method out for this. My whole layout is like -

<?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>
Pradyut Bhattacharya
  • 5,243
  • 13
  • 50
  • 80

0 Answers0