title: android progress bar on videoview
body: <p>I have a gridview where each view is a videoview that show rtsp strems.</p>
  
  <p>I want a circle progress bar that run until video starts.</p>
  
  <p>I have a problem, video starts but than disappear, black screen. This only using relative layout, If I use Linear layout the progress bar logic works fine, but that is not what I want.</p>
  
  <p>this is my adapter code for gridview</p>
  
  <pre><code>public class VideoAdapter extends BaseAdapter {
      private static final String TAG = VideoAdapter.class.getName();
      private Context mContext;
      private GridView mGv;   
      private int ROW_NUMBER = 3;
      private int COL_NUMBER = 3;
       private String[] mvideoSrc;
  
  
      public VideoAdapter(Context c, GridView gv,int col,int row,String[] videosrc) {
          mContext = c;
          mGv=gv;
          ROW_NUMBER=row;
          COL_NUMBER=col;
          mvideoSrc=videosrc;
  
      }
  
      public int getCount() {
          return ROW_NUMBER*COL_NUMBER;
      }
  
      public Object getItem(int position) {
          return null;
      }
  
      public long getItemId(int position) {
          return 0;
      }
  
      // create a new VideoView for each item referenced by the Adapter
      @SuppressLint("NewApi")
      public View getView(int position, View convertView, ViewGroup parent) {
          LayoutInflater inflater = (LayoutInflater) mContext
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
  
              View gridView;
          if (convertView == null) {  // if it's not recycled, initialize some attributes
  
  
              gridView = new View(mContext);
              gridView = inflater.inflate(it.nexera.visiamobile.R.layout.videoview_layout, null);
              final ProgressBar progressBar = (ProgressBar) gridView.findViewById(it.nexera.visiamobile.R.id.grid_progress);
              VideoView videoView = (VideoView) gridView.findViewById(it.nexera.visiamobile.R.id.grid_videoview);
  
  
              WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
              Display display = wm.getDefaultDisplay();
              int width=0;
              int height=0;
  
              if (android.os.Build.VERSION.SDK_INT &gt;= 13){
                  Point size = new Point();
                  display.getSize(size);
                  width = size.x;
                  height = size.y;
              }
              else{
                  width = display.getWidth();
                  height = display.getHeight();
  
              }
              // Calculate ActionBar height
              TypedValue tv = new TypedValue();
              int actionBarHeight=0;
              if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true))
              {
                  actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data,mContext.getResources().getDisplayMetrics());
              }
  
  
              TextView textview = (TextView) ((Activity) mContext).findViewById (it.nexera.visiamobile.R.id.txt_grid); 
  
              int textview_height=textview.getHeight();
              height=height-actionBarHeight-textview_height;
              RelativeLayout.LayoutParams param = new RelativeLayout.LayoutParams(
                      (width/COL_NUMBER),
                      (height/ROW_NUMBER));
  //          LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(
  //                  (width/COL_NUMBER),
  //                    (height/ROW_NUMBER));
  
              videoView.setLayoutParams(param);
              videoView.setFocusable(false);
              videoView.setFocusableInTouchMode(false);
  
             Uri video = Uri.parse(mvideoSrc[position]);
  
              videoView.setVideoURI(video);
              progressBar.setVisibility(View.VISIBLE);
  
              videoView.setOnPreparedListener(new OnPreparedListener() {
  
                  @Override
                  public void onPrepared(MediaPlayer mp) {
  
                      //ProgressBar progressBar = (ProgressBar) gridView.findViewById(it.nexera.visiamobile.R.id.grid_progress);
                      progressBar.setVisibility(View.GONE);
                      mp.start();
  
                  }
              });
            //  videoView.start();
  
          } else {
              gridView = (View) convertView;
          }
          return gridView;
      }
  
  //
  
  }
  </code></pre>
  
  <p>and this is my layout for each item of gridview, you can ignore comment line for linear layout</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
   &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/GridItem"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:orientation="vertical"
     android:gravity="center_horizontal"
    &gt;
  
       &lt;ProgressBar
           android:id="@+id/grid_progress"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           style="@android:style/Widget.ProgressBar.Large"
           android:layout_marginRight="5dp"
           android:visibility="gone"
           android:layout_centerInParent="true"
      android:layout_gravity="center"
            /&gt;
        &lt;VideoView 
          android:id="@+id/grid_videoview"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
  
      &lt;/VideoView&gt;
  
  
  
  &lt;/RelativeLayout&gt;
  
   &lt;!--
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/GridItem"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:orientation="vertical"
     android:gravity="center_horizontal"
    &gt;
  
       &lt;ProgressBar
           android:id="@+id/grid_progress"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           style="@android:style/Widget.ProgressBar.Large"
           android:layout_marginRight="5dp"
           android:visibility="gone"
      android:layout_gravity="center"
            /&gt;
        &lt;VideoView 
          android:id="@+id/grid_videoview"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"&gt;
  
  
      &lt;/VideoView&gt;
  
  
  
  &lt;/LinearLayout&gt;
  
   --&gt;
  </code></pre>