title: Use smoothScrollTo in Fragment
body: <p>I have following situation:</p>
  
  <p>I'm using a Navigation Drawer to make the user easily navigate between different topics.</p>
  
  <p>You can find a picture here: </p>
  
  <p><a href="https://drive.google.com/file/d/0B2gMUEFwlGRfSHRzVlptYmFQTXc/edit?usp=sharing" rel="nofollow">https://drive.google.com/file/d/0B2gMUEFwlGRfSHRzVlptYmFQTXc/edit?usp=sharing</a></p>
  
  <p>When clicking on a heading, like <strong>General</strong> the only the main content view is replaced, by using a fragment and a layout file.
  But when the user clicks on a subheading, like <strong>Gameplay</strong>, the layout changes, AND it should scroll down to a specifc view in the layout.</p>
  
  <p>So in my fragment class I'm using the "onViewCreated" method and the smoothScrollTo method, provided by a ScrollView. The ScrollView and the RelativeLayout are both not null, and set to the right id, set in "onCreateView"</p>
  
  <p>Codesnippets:</p>
  
  <pre><code>@Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
      super.onViewCreated(view, savedInstanceState);
      if (getArguments().getBoolean(ARG_BOOL)) {
          scrollView = (ScrollView)getView().findViewById(scrollID);
          relativeLayout = (RelativeLayout)getView().findViewById(relativeID);
  
          ((ScrollView)getView().findViewById(scrollID)).smoothScrollTo(
                  0, (getView().findViewById(relativeID)).getLeft());
  
          Toast.makeText(getApplicationContext(), "SCROLL",Toast.LENGTH_SHORT).                  
                  show();
          }
       }
  </code></pre>
  
  <p>The problem is that it is not executing the "smoothScrollTo" method, while the toast gets executed.</p>
  
  <p>Here I call the fragment (boolean scroll is used to control the smoothScrollTo method):</p>
  
  <pre><code>private void selectItem(int Id, boolean scroll) {
      Fragment fragment = new ContentFragment();
      Bundle args = new Bundle();
      args.putBoolean(ContentFragment.ARG_BOOL, scroll);
      args.putInt(ContentFragment.ARG_ITEM_ID, Id);
      fragment.setArguments(args);
  
      // Insert the fragment by replacing any existing fragment
      FragmentManager fragmentManager = getFragmentManager();
      fragmentManager.beginTransaction()
              .replace(R.id.content_frame, fragment)
              .commit();
      // Highlight the selected item, update the title, and close the drawer
      TextView textView = (TextView) findViewById(Id);
      getActionBar().setTitle(textView.getText());
      mDrawerLayout.closeDrawer(mDrawerList);
  } 
  </code></pre>
  
  <p>Thanks for your help ;-)</p>
  
  <p><strong>EDIT:</strong> 
  <strong><em>SOLUTION:</em></strong></p>
  
  <pre><code>if (getArguments().getBoolean(ARG_BOOL)) {
      getView().findViewById(scrollID).post(new Runnable() {
          @Override
          public void run() {
              ((ScrollView) getView().findViewById(scrollID)).
                  smoothScrollTo(0, (getView().findViewById(relativeID)).getTop());
          }
      });
  }
  </code></pre>