title: RemoteViews ListView setScrollPosition Misses
body: <p>I'm working on an app widget that contains a ListView.  I want to be able to have it scroll to a specific row when it refreshes, and I'm using <code>RemoteViews.setRelativeScrollPosition</code> to do so, but it virtually always misses, either scrolling too far so the desired row is halfway off the top, or not far enough, so it's somewhere below the top of the widget.  I want it to be lined up right at the top of the widget.  I've tried using <code>setScrollPosition</code> instead of <code>setRelativeScrollPosition</code>, but then it doesn't scroll at all (the desired row is still shown, just farther down).</p>
  
  <p>Am I doing something wrong, missing something, or is it just not possible to scroll a ListView to a specific position in a widget?  I don't need the scrolling effect, I'd be happy if it just suddenly appeared in the right spot.</p>
  
  <p>Here's my main widget layout:</p>
  
  <pre><code>&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:orientation="vertical"
            android:padding="@dimen/widget_margin"
            style="@style/AppTheme.WidgetMain"&gt;
  
  &lt;RelativeLayout android:id="@+id/title_layout"
      android:layout_height="wrap_content"
      android:layout_margin="1dp"
      android:layout_width="match_parent"
      style="@style/AppTheme.Title.Background"&gt;
      &lt;TextView android:id="@+id/appwidget_title"
                android:contentDescription="@string/appwidget_title"
                android:layout_alignParentStart="true"
                android:layout_centerVertical="true"
                android:layout_height="wrap_content"
                android:layout_margin="1dp"
                android:layout_toStartOf="@+id/button_refresh"
                android:layout_width="wrap_content"
                android:paddingEnd="2dp"
                android:paddingStart="2dp"
                android:text="@string/appwidget_title"
                style="@style/AppTheme.Title" /&gt;
      &lt;ImageButton android:id="@+id/button_refresh"
                   android:contentDescription="@string/button_refresh"
                   android:layout_centerVertical="true"
                   android:layout_height="wrap_content"
                   android:layout_marginEnd="20dp"
                   android:layout_toStartOf="@id/button_settings"
                   android:layout_width="wrap_content"
                   android:src="@drawable/ic_refresh"
                   style="@style/AppTheme.WidgetMain.Button" /&gt;
      &lt;ImageButton android:id="@+id/button_settings"
                   android:contentDescription="@string/button_settings"
                   android:layout_alignParentEnd="true"
                   android:layout_centerVertical="true"
                   android:layout_height="wrap_content"
                   android:layout_marginEnd="10dp"
                   android:layout_width="wrap_content"
                   android:src="@android:drawable/ic_menu_preferences"
                   style="@style/AppTheme.WidgetMain.Button" /&gt;
  &lt;/RelativeLayout&gt;
  
  &lt;LinearLayout android:id="@+id/header_layout"
      android:layout_height="wrap_content"
      android:layout_marginEnd="1px"
      android:layout_marginStart="1px"
      android:layout_width="match_parent"
      android:orientation="horizontal"
      style="@style/AppTheme.Background" /&gt;
  
  &lt;ListView android:id="@+id/grid"
            android:divider="@null"
            android:layout_gravity="center"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:scrollbars="none" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>The ListView is populated in code with rows of the following layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/box"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:layout_gravity="fill"
            android:layout_height="83dp"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:orientation="vertical"
            style="@style/AppTheme.Background"&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>Then, I scroll it in my <code>RemoteViewsService</code> with the following:</p>
  
  <pre><code>@Override
      public void onDataSetChanged()
      {
          /* Scroll the view if the option is checked */
          if ( _context.getSharedPreferences(
              MainPreferencesFragment.getSharedPreferencesFileName( _appWidgetId ),
              Context.MODE_PRIVATE ).
              getBoolean( MainPreferencesFragment.PREF_KEY_SCROLL, false ) )
              {
                  /* Set up the handler thread */
                  final HandlerThread thread = new HandlerThread( "Widget-worker" );
                  thread.start();
                  Handler queue = new Handler( thread.getLooper() );
                  /* Post a delayed action to the thread to set the scroll position */
                  queue.postDelayed( new Runnable()
                  {
                      @Override
                      public void run()
                      {
                          String packageName = _context.getPackageName();
                          RemoteViews rv = new RemoteViews( packageName, R.layout.widget );
                          rv.setRelativeScrollPosition( R.id.grid, _currentPosition );
                          AppWidgetManager appWidgetManager = AppWidgetManager.getInstance( _context );
                          appWidgetManager.partiallyUpdateAppWidget( _appWidgetId, rv );
                          thread.quitSafely();
                      }
                  }, 100 );
              }
      }
  </code></pre>