title: How to set header layout in video view
body: <p>I'm working in video view that contain title layout. I have attached the header layout in video view. what is my problem is when i touch on video view both title layou and mediacontolls should shown, After some time both(title layou and media controls) should disappear. Simply whenever the media controlls show the title layou should show , then whenever media controlls disapper the title layou should disapper.</p>
  
  <p><a href="https://i.stack.imgur.com/dxgnM.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dxgnM.jpg" alt="this is the my video view"></a></p>
  
  <p><strong>XML CODE</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:layout_gravity="center"
  android:background="#000"&gt;
  
  &lt;RelativeLayout
      android:layout_width="fill_parent"
      android:layout_height="match_parent"&gt;
  
      &lt;VideoView
          android:id="@+id/playerview"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_alignParentLeft="true"
          android:layout_alignParentRight="true"
          android:layout_centerInParent="true"
          android:layout_gravity="center_vertical" /&gt;
  
      &lt;LinearLayout
          android:id="@+id/share_layout"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
         android:background="@android:color/transparent"
          android:padding="10dp"
          android:layout_alignParentBottom="true"
          android:layout_alignParentRight="true"
          android:layout_alignParentEnd="true"
          android:layout_marginBottom="80dp"
          android:orientation="horizontal"&gt;
  
          &lt;ImageButton
              android:id="@+id/twitter_button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:src="@drawable/twitter"
              android:paddingTop="20dp"
              android:paddingRight="10dp"
              android:background="@android:color/transparent" /&gt;
  
          &lt;ImageButton
              android:id="@+id/facebook_button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:src="@drawable/facebook"
              android:paddingRight="10dp"
              android:layout_below="@+id/twitter_button"
              android:background="@android:color/transparent"
              android:paddingTop="20dp"/&gt;
  
          &lt;ImageButton
              android:visibility="gone"
              android:id="@+id/share_Button"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:src="@drawable/share_icon"
              android:background="@android:color/transparent"
              android:paddingTop="20dp"
              android:layout_below="@+id/facebook_button"/&gt;
  
      &lt;/LinearLayout&gt;
  
  &lt;/RelativeLayout&gt;
  
  
  &lt;RelativeLayout
      android:id="@+id/header_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:background="#BF000000"
      android:padding="10dp"&gt;
  
      &lt;ImageButton
          android:id="@+id/imageBtnclose"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:src="@drawable/close_button"
          android:background="@android:color/transparent" /&gt;
  
      &lt;TextView
          android:id="@+id/videoTitletv"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:gravity="center_vertical"
          android:text="video title"
          android:textColor="#ffffff"
          android:paddingLeft="10dp"
          android:layout_centerVertical="true"
          android:layout_toRightOf="@+id/imageBtnclose"
          android:layout_toEndOf="@+id/imageBtnclose" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>JAVA CODE</strong></p>
  
  <pre><code>public class VideoAdPlayer extends Activity {
  // private boolean vbBackkeyPressed = false;
  private VideoView myVideoView;
  private RelativeLayout myLinearClose;
  LinearLayout shareLayout;
  private ProgressDialog progressDialog;
  private MediaController mediaControls;
  private int adshowTime = 30;
  Timer mTimer = new Timer();
  boolean MidrollPlayed = false;
  YuMeInterface yumeInterface;
  ImageButton imgCloseBtn;
  boolean isPortrait = true;
  ImageButton faceBookButton, twitterButton, shareButton;
  public static VideoAdPlayer playerActivity = null;
  
  public static Context playerContext = null;
  public static int playedAdType = 1;
  public static boolean isActivityrun = false;
  
  boolean isPrerollAds;
  boolean isPostrollAds;
  boolean isMidrollAds;
  boolean isShareClicked = false;
  
  @SuppressLint("ClickableViewAccessibility")
  @SuppressWarnings("deprecation")
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      String myString = android.os.Build.VERSION.RELEASE;
      System.out.println(myString);
      setContentView(R.layout.video);
      Intent intent = getIntent();
      String playVideoUrl = "";
      String videoThumb = "";
  
      getActionBar().hide();
  
  
      playerActivity = this;
      playerContext = this.getApplicationContext();
  
      myLinearClose = (RelativeLayout) findViewById(R.id.header_layout);
      shareLayout = (LinearLayout) findViewById(R.id.share_layout);
      TextView videoTxtview = (TextView)findViewById(R.id.videoTitletv);
  
      faceBookButton = (ImageButton) findViewById(R.id.facebook_button);
      twitterButton = (ImageButton) findViewById(R.id.twitter_button);
      shareButton = (ImageButton) findViewById(R.id.share_Button);
  
      shareLayout.setOrientation(LinearLayout.HORIZONTAL);
      videoTxtview.setText("DEFAULT TITLE");
  
      if (mediaControls == null) {
  
          mediaControls = new MediaController(VideoAdPlayer.this);
  
      }
      myVideoView = (VideoView) findViewById(R.id.playerview);
      imgCloseBtn = (ImageButton) findViewById(R.id.imageBtnclose);
  
      progressDialog = createProgressDialog(VideoAdPlayer.this);
      progressDialog.show();
  
      imgCloseBtn.setOnClickListener(new OnClickListener() {
  
          @Override
          public void onClick(View v) {
  
              JSONObject msgPlayer = new JSONObject();
              try {
                  msgPlayer.put("finished", false);
                  YumeIntegration.callbackContext.success(msgPlayer);
              } catch (JSONException e) {
  
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
  
              finish();
          }
      });
      try {
  
          myVideoView.setVideoURI(Uri.parse(playVideoUrl));
  
      } catch (Exception e) {
          Log.e("Error", e.getMessage());
          e.printStackTrace();
      }
  
      myVideoView.requestFocus();
      myVideoView.setZOrderOnTop(false);
      playedAdType = 1;
  
      myVideoView.setOnTouchListener(new View.OnTouchListener() {
  
          @Override
          public boolean onTouch(View v, MotionEvent event) {
              // TODO Auto-generated method stub
              if (!myLinearClose.isShown()) {
                  if (!isPortrait) {
                      myLinearClose.setVisibility(View.VISIBLE);
                  }
  
                  myLinearClose.postDelayed(new Runnable() {
                      @Override
                      public void run() {
                          if (!isPortrait) {
                                   myLinearClose.setVisibility(View.INVISIBLE);
                          }
                      }
                  }, 3000);
  
              } else {
                  if (myLinearClose.isShown()) {
  
                      if (!isPortrait) {
                          myLinearClose.setVisibility(View.INVISIBLE);
                      }
                  }
              }
              return false;
          }
      });
  
      myVideoView.setMediaController(mediaControls);
  
      myVideoView.setOnPreparedListener(new OnPreparedListener() {
  
          public void onPrepared(final MediaPlayer mediaPlayer) {
              progressDialog.dismiss();
              myLinearClose.setVisibility(View.VISIBLE);
              int duration = myVideoView.getDuration();
              Log.e("total duration", String.valueOf(duration));
              final int totalSeconds = duration / 1000;
              final int postrollads = totalSeconds - 25;
              final int MidrollAdsShows = totalSeconds / 2;
  
  
              Log.e("total durationin secods", String.valueOf(totalSeconds));
              try {
  
                  mTimer.scheduleAtFixedRate(new TimerTask() {
  
                      @Override
                      public void run() {
  
                          int currentTime = myVideoView.getCurrentPosition() / 1000;
                          /*
                           * if (currentTime &gt; postrollads &amp;&amp;
                           * !postRolladsInit) { postRolladsInit = true; try {
                           * yumeInterface.updatesSdkParams(3); } catch
                           * (YuMeException e) { e.printStackTrace(); }
                           *
                           * } */
  
                          if (currentTime &gt; MidrollAdsShows &amp;&amp; !MidrollPlayed) {
  
                              adshowTime += 30;
                              MidrollPlayed = true;
                              playedAdType = 2;
                              if (isMidrollAds) {
                                  if (yumeInterface.sdkIsAdAvailable()) {
  
                                      myVideoView.pause();
                                      final Intent mainIntent = new Intent(VideoAdPlayer.this, AdView.class);
  
                                      startActivityForResult(mainIntent, 3);
                                  }
                              }
  
                          }
                      }
                  }, 0, 2000);
  
                  if (!mediaControls.isShowing()) {
                      mediaControls.show();
                      Toast.makeText(VideoAdPlayer.this,"YES",Toast.LENGTH_SHORT).show();
                  }
  
                  myLinearClose.setVisibility(View.VISIBLE);
                  myLinearClose.postDelayed(new Runnable() {
                      @Override
                      public void run() {
                          // TODO Auto-generated method stub
                          if (!isPortrait){
                              myLinearClose.setVisibility(View.INVISIBLE);
                          }
                      }
                  }, 3000);
  
              } catch (Exception ex) {
  
              }
  
          }
      });
  
   myVideoView.setOnCompletionListener(new OnCompletionListener() {
  
          @Override
          public void onCompletion(MediaPlayer mp) {
              mTimer.cancel();
  
              JSONObject msgPlayer = new JSONObject();
              try {
                  msgPlayer.put("finished", true);
                  YumeIntegration.callbackContext.success(msgPlayer);
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              playedAdType = 3;
              // finish();
              if (isPostrollAds) {
                  if (yumeInterface.sdkIsAdAvailable()) {
  
                      final Intent mainIntent = new Intent(VideoAdPlayer.this, AdView.class);
  
                      startActivityForResult(mainIntent, 3);
                  } else {
                      finish();
                  }
              } else {
                  finish();
              }
  
  
          }
      });
  
   public static ProgressDialog createProgressDialog(Context mContext) {
      ProgressDialog dialog = new ProgressDialog(mContext);
      try {
          dialog.show();
      } catch (BadTokenException e) {
  
      }
  
      dialog.setCancelable(false);
      dialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
      dialog.setContentView(R.layout.progressdialog);
      // dialog.setMessage(Message);
      return dialog;
  }
  
  protected void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
      // check if the request code is same as what is passed here it is 3
      if (requestCode == 3) {
  
          myVideoView.requestFocus();
          myVideoView.start();
          myVideoView.setZOrderOnTop(false);
  
      }
  }
  
  @Override
  public void onConfigurationChanged(Configuration newConfig) {
      super.onConfigurationChanged(newConfig);
  
      if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
          myLinearClose.setVisibility(View.VISIBLE);
          shareLayout.setOrientation(LinearLayout.VERTICAL);
          myVideoView.requestFocus();
          isPortrait = false;
  
          landscapeMode();
  
      } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
          shareLayout.setOrientation(LinearLayout.HORIZONTAL);
          myVideoView.requestFocus();
          isPortrait = true;
          myLinearClose.setVisibility(View.VISIBLE);
  
          portraitMode();
  
      }
  }
  
  private void portraitMode() {
      isPortrait = true;
      faceBookButton.setVisibility(View.VISIBLE);
      twitterButton.setVisibility(View.VISIBLE);
      shareButton.setVisibility(View.VISIBLE);
      shareButton.setVisibility(View.GONE);
  
      if (!mediaControls.isShowing()) {
          mediaControls.show();
          Toast.makeText(VideoAdPlayer.this, "YES", Toast.LENGTH_SHORT).show();
      }
  
      myLinearClose.setVisibility(View.VISIBLE);
      myLinearClose.postDelayed(new Runnable() {
          @Override
          public void run() {
              // TODO Auto-generated method stub
              if (!isPortrait) {
                  myLinearClose.setVisibility(View.INVISIBLE);
              }
          }
      }, 3000);
  }
  
  private void landscapeMode() {
      isPortrait = false;
  
      if (!mediaControls.isShowing()) {
          mediaControls.show();
          Toast.makeText(VideoAdPlayer.this, "YES", Toast.LENGTH_SHORT).show();
      }
  
      myLinearClose.setVisibility(View.VISIBLE);
      myLinearClose.postDelayed(new Runnable() {
          @Override
          public void run() {
              // TODO Auto-generated method stub
              if (!isPortrait) {
                  myLinearClose.setVisibility(View.INVISIBLE);
              }
          }
      }, 3000);
  
      faceBookButton.setVisibility(View.GONE);
      twitterButton.setVisibility(View.GONE);
      shareButton.setVisibility(View.VISIBLE);
      shareButton.setVisibility(View.VISIBLE);
  
      shareButton.setOnClickListener(new OnClickListener() {
          @Override
          public void onClick(View v) {
  
              if (!isPortrait) {
                  if (!isShareClicked) {
                      isShareClicked = true;
                      faceBookButton.setVisibility(View.GONE);
                      twitterButton.setVisibility(View.GONE);
                  } else {
                      isShareClicked = false;
                      faceBookButton.setVisibility(View.VISIBLE);
                      twitterButton.setVisibility(View.VISIBLE);
                  }
              }
          }
      });
  
  }
  </code></pre>