title: Android fragment blank
body: <p>I have a fragment which has RelativeLayout and a ImageView.</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:tools="http://schemas.android.com/tools"
  android:id="@+id/pagelayout"
  android:layout_below="@layout/toolbar"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"
  android:background="@color/aqua_blue"
  tools:context="MainActivityFragment"&gt;
  
  &lt;ImageView
      android:id="@+id/pdfImage"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="@android:color/white"
      android:adjustViewBounds="true"
      android:scaleType="fitStart"/&gt;
  </code></pre>
  
  <p></p>
  
  <p>I render a pdfpage as an image and display in the image view in onViewCreated as follows.</p>
  
  <pre><code> pageLayout = (RelativeLayout)  rootView.findViewById(R.id.pagelayout);
      //Retain view references.
      mImageView = (ImageView) rootView.findViewById(R.id.pdfImage);        
  
      // Show the first page by default.
      mCurrentPageNum = pdfRenderer.getmCurrentPageNum();
      if (mCurrentPageNum == 0) {
          mCurrentPageNum = 1;
          pdfRenderer.setmCurrentPageNum(mCurrentPageNum);
      }
      showPage(mCurrentPageNum, true, this.activity);
  
      //get screen size
      DisplayMetrics metrics = context.getResources().getDisplayMetrics();
      scrwidth = metrics.widthPixels;
      scrheight = pdfRenderer.getPDFImage().getHeight(); 
  
      pageControlsList = pdfRenderer.GetPageControls();
      if (pageControlsList != null) {
          if (pageControlsList.size() &gt; 0) {
              generateControls();
              showPage(mCurrentPageNum, true, this.activity);
          }
      }
  </code></pre>
  
  <p>When the user swipe on the page, I navigate to next page or previous page. For that I am calling the following function written in fragment from Mainactivity.</p>
  
  <pre><code>public void Readpage(int index, boolean PdfReload, Activity activity)
  {
      //context=activity;
      //pageLayout = (RelativeLayout)  rootView.findViewById(R.id.pagelayout);
      //mImageView = (ImageView) rootView.findViewById(R.id.pdfImage);
      showPage(index, true, activity);
      pageControlsList = pdfRenderer.GetPageControls();
      if (pageControlsList != null) {
          generateControls();            
      }
  }
  </code></pre>
  
  <p>Generatecontrols method is called if there are any controls in the page and generated dynamically. The code is as follows (given only one control for sample).</p>
  
  <pre><code> public void generateControls() {
      //iterate loop to create each control
          for (Map.Entry&lt;Integer, PageElement&gt; ctrl : pageControlsList.entrySet()) {
              Integer ctrlKey = ctrl.getKey();
              PageElement pageField = ctrl.getValue();
              String name = pageField.getName();
              int type = pageField.getType();
  
  
              int pdfw = (int) pdfRenderer.getPage_width();
              int pdfh = (int) pdfRenderer.getPage_height();
  
              //get dimensions of the control
              int left = (int) pageField.getLeft();
              int top = (int) pageField.getTop();
              int right = (int) pageField.getRight();
              int bottom = (int) pageField.getBottom();
              int width = (int) pageField.getWidth();
              int height = (int) pageField.getHeight();
  
              //calculate dimensions w.r.t. screen size
              int ctrlW = scrwidth * width / pdfw;
              int ctrlH = scrheight * height / pdfh;
              int ctrlLeft = (int) (scrwidth * left) / pdfw;
              int ctrlTop = (int) (((scrheight * (pdfh - top)) / pdfh));
              int ctrlRight = (int) (scrwidth * right) / pdfw;
              int ctrlBottom = (int) (scrheight * bottom / pdfh);
  
              //set dimensions of the control with layout parameters
              RelativeLayout.LayoutParams ctrllp = new RelativeLayout.LayoutParams(ctrlW, ctrlH);
              ctrllp.setMargins(ctrlLeft, ctrlTop, 0, 0);
  
  
              //generate controls based on the type of control
              if (type == 2) { //checkbox
                  CheckBox myChkBox = new CheckBox(context);
                  myChkBox.setId(ctrlKey);
                  myChkBox.setFocusable(false);
                  myChkBox.setEnabled(false);
                  if (pageField.ExportValue().contains("Off"))
                      myChkBox.setChecked(false);
                  else
                      myChkBox.setChecked(true);
  
                  pageLayout.setLayoutParams(ctrllp);
                  pageLayout.addView(myChkBox, ctrllp);
  }
  </code></pre>
  
  <p>It works fine even if the first page contains any controls or not. Once I swipe if any other page contains controls then i can see only a blank fragment. If no controls then I can see everything working perfectly. I tried many ways but none worked for me. Any help please.</p>