1. Are you ready for the Galaxy S20? Here is everything we know so far!

HELP How to adapat screen size of a Relative Layout videoView

Discussion in 'Android Development' started by Armczbt, Jul 20, 2021.

  1. Armczbt

    Armczbt Lurker
    Thread Starter

    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 :

    Code (Java):
    1. <VideoView
    2.         android:id="@+id/video_view"
    3.         android:keepScreenOn="true"
    4.         android:layout_width="fill_parent"
    5.  
    6.         android:layout_alignParentRight="true"
    7.         android:layout_alignParentLeft="true"
    8.         android:layout_alignParentTop="true"
    9.         android:layout_alignParentBottom="true"
    10.         android:layout_height="fill_parent"/>
    and the code for the button :

    Code (Java):
    1. case R.id.videoView_track:
    2.  
    3.             DisplayMetrics metrics1 = new DisplayMetrics();
    4.             getWindowManager().getDefaultDisplay().getMetrics(metrics1);
    5.             android.widget.RelativeLayout.LayoutParams initialParams = (android.widget.RelativeLayout.LayoutParams) videoView.getLayoutParams();
    6.  
    7.             if (clickCount==1){
    8.                 initialParams.alignWithParent = true;
    9.                 videoView.setLayoutParams(initialParams);
    10.                 clickCount=0;
    11.             }
    12.             else if (clickCount==0){
    13.                 DisplayMetrics metrics = new DisplayMetrics();
    14.                 getWindowManager().getDefaultDisplay().getMetrics(metrics);
    15.                 android.widget.RelativeLayout.LayoutParams params = (android.widget.RelativeLayout.LayoutParams) videoView2.getLayoutParams();
    16.                 params.width = metrics.widthPixels;
    17.                 params.height = metrics.heightPixels;
    18.                 params.leftMargin = 0;
    19.                 params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    20.  
    21.                 videoView.setLayoutParams(params);
    22.                 clickCount=1;
    23.             }
    24.             break;
    25.     }
    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
     



    1. Download the Forums for Android™ app!


      Download

       
Loading...

Share This Page

Loading...