• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

HELP How to adapat screen size of a Relative Layout videoView

Armczbt

Lurker
Jul 20, 2021
2
0
Hi, for an app that is a Video Player, I want to create a button that stretches the video to the edges of the screen. I have made a RelativeLayout :

Java:
<VideoView
        android:id="@+id/video_view"
        android:keepScreenOn="true"
        android:layout_width="fill_parent"

        android:layout_alignParentRight="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_height="fill_parent"/>

and the code for the button :

Java:
case R.id.videoView_track:

            DisplayMetrics metrics1 = new DisplayMetrics();
            getWindowManager().getDefaultDisplay().getMetrics(metrics1);
            android.widget.RelativeLayout.LayoutParams initialParams = (android.widget.RelativeLayout.LayoutParams) videoView.getLayoutParams();

            if (clickCount==1){
                initialParams.alignWithParent = true;
                videoView.setLayoutParams(initialParams);
                clickCount=0;
            }
            else if (clickCount==0){
                DisplayMetrics metrics = new DisplayMetrics();
                getWindowManager().getDefaultDisplay().getMetrics(metrics);
                android.widget.RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) videoView2.getLayoutParams();
                params.width = metrics.widthPixels;
                params.height = metrics.heightPixels;
                params.leftMargin = 0;
                params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);

                videoView.setLayoutParams(params);
                clickCount=1;
            }
            break;
    }

The "else" part works, the video is first stretched and when i click the button it adapts to the screen size without stretching but I don't know how to do the contrary (the "if part"), how to kind of reset the params...

Thanks for your help
 

BEST TECH IN 2023

We've been tracking upcoming products and ranking the best tech since 2007. Thanks for trusting our opinion: we get rewarded through affiliate links that earn us a commission and we invite you to learn more about us.

Smartphones