设置android小部件的初始滚动位置
作者:互联网
我有一个基于集合的小部件,我想更改初始滚动位置.
我已经在我的RemoteViewsFactory中尝试过以下方法.
views.setScrollPosition(R.id.widgetList, myDesiredPosition);
AppWidgetManager.getInstance(mContext).partiallyUpdateAppWidget(mAppWidgetId, views);
但不幸的是它不起作用..我也试图在我的WidgetProvider中设置该权限,但是没有起作用.
所以,请..有没有办法改变包裹到远程视图的列表视图的滚动位置?谢谢..
解决方法:
我已经在RemoteViewsService.RemoteViewsFactory的onDataSetChanged函数中完成了此操作.我必须添加一个AsynTask来延迟滚动.如果getLoadingView返回的视图与getViewAt返回的所有视图的高度相同,则可能不需要这样做.
@Override
public void onDataSetChanged() {
new AsyncTask<Integer, Void, Void>() {
@Override
protected Void doInBackground(Integer[] params) {
int widgetId = params[0];
int count = params[1];
try {
Thread.sleep(800);
} catch (InterruptedException e) {
Log.d(TAG, "Scroll thread was interrupted");
}
String packageName = context.getPackageName();
RemoteViews rv = new RemoteViews(packageName, R.layout.widget_layout);
rv.setInt(R.id.list_view, "smoothScrollToPosition", count);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
appWidgetManager.partiallyUpdateAppWidget(widgetId, rv);
return null;
}
}.execute(this.appWidgetId, this.rowCount);
}
标签:android-listview,android-widget,remoteview,android 来源: https://codeday.me/bug/20191122/2061356.html