本文整理匯總了Java中android.support.v7.widget.RecyclerView.smoothScrollToPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java RecyclerView.smoothScrollToPosition方法的具體用法?Java RecyclerView.smoothScrollToPosition怎麽用?Java RecyclerView.smoothScrollToPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v7.widget.RecyclerView
的用法示例。
在下文中一共展示了RecyclerView.smoothScrollToPosition方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testOnRecyclerViewScroll_ShouldChangeScrollPosition
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void testOnRecyclerViewScroll_ShouldChangeScrollPosition() throws Exception {
int scrollPosition = 1;
RecyclerView recyclerView = (RecyclerView)activity.findViewById(R.id.recyclerView);
ShadowRecyclerView shadowRecyclerView = (ShadowRecyclerView) ShadowExtractor.extract(recyclerView);
recyclerView.smoothScrollToPosition(scrollPosition);
assertEquals(scrollPosition, shadowRecyclerView.getSmoothScrollPosition());
}
示例2: testOnToolbarClicked_RecyclerViewShouldScrollToTop
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Test
public void testOnToolbarClicked_RecyclerViewShouldScrollToTop() throws Exception {
int scrollPosition = 1;
int topScrollPosition = 0;
Toolbar toolbar = (Toolbar)activity.findViewById(R.id.toolbar);
RecyclerView recyclerView = (RecyclerView)activity.findViewById(R.id.recyclerView);
ShadowRecyclerView shadowRecyclerView = (ShadowRecyclerView) ShadowExtractor.extract(recyclerView);
recyclerView.smoothScrollToPosition(scrollPosition);
toolbar.performClick();
assertEquals(topScrollPosition, shadowRecyclerView.getSmoothScrollPosition());
}
示例3: insertItems
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
/**
* 插入條目
*/
public static void insertItems(SimpleAdapter adapter, RecyclerView view) {
//loadTimes自增
loadTimes++;
try {
int count = Math.min(MyApplication.books.length(), MyApplication.currentItemIndex + 10);
for (int i = MyApplication.currentItemIndex; i < count; i++) {
JSONObject jsonObject = MyApplication.books.getJSONObject(i);
Book book = new Book();
book.setBookID(jsonObject.getInt("BookID"));
book.setPageCount(jsonObject.getInt("PageCount"));
book.setScore((float) jsonObject.getDouble("Score"));
book.setTitle(jsonObject.getString("Title"));
book.setAuthor(jsonObject.getString("Author"));
book.setCoverUrl(jsonObject.getString("CoverURL"));
book.setContentUrl(jsonObject.getString("ContentURL"));
book.setFileName(jsonObject.getString("FileName"));
MyApplication.currentItemIndex++;
//將書本信息插入Adapter
adapter.insert(book, i);
}
if (loadTimes == 1)
view.smoothScrollToPosition(0);
} catch (JSONException e) {
e.printStackTrace();
}
}
示例4: onCreateView
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
isDialogReady = true;
// initialize realm object
realm = Realm.getDefaultInstance();
// get the arguments passed in
Bundle bundle = getArguments();
String id = bundle.getString(MainActivity.TAG_SCHEDULE_ID);
schedule = realm.where(Schedule.class).equalTo("id", id).findFirst();
// set up title
((MainActivity) getActivity()).getSupportActionBar().setTitle(schedule.getLanguage() + " - " + schedule.getTitle());
// load views
rootView = inflater.inflate(R.layout.fragment_main, container, false);
// skip over all days that have already been completed
findNextIncompleteDay();
// set up adapter and subscribe to clicks on a day
int currentDayPosition = schedule.getSchedule().indexOf(currentDay);
adapter = new ScheduleAdapter(currentDayPosition, schedule.getSchedule(), getContext());
adapter.asObservable().subscribe(this::showDay);
// set up recycler view
RecyclerView recyclerView = (RecyclerView) rootView.findViewById(R.id.scheduleRecyclerView);
recyclerView.setAdapter(adapter);
RecyclerView.LayoutManager layoutManager = new GridLayoutManager(getActivity(), 7);
recyclerView.setLayoutManager(layoutManager);
recyclerView.smoothScrollToPosition(currentDayPosition);
return rootView;
}
示例5: perform
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
public void perform(UiController uiController, View view) {
RecyclerView recyclerView = (RecyclerView) view;
recyclerView.smoothScrollToPosition(position);
}
示例6: onCreate
import android.support.v7.widget.RecyclerView; //導入方法依賴的package包/類
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_demo_1);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
mToolbar.setTitle(R.string.title);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
mRvTag = (RecyclerView) findViewById(R.id.rv_tag);
mList = new ArrayList<>();
mAdapter = new TagAdapter(this, mList, new TagAdapter.OnTagClickListener() {
@Override
public void onRemoved(String removedTag) {
Log.i(TAG, "onRemoved: =============removed tag:" + removedTag);
}
@Override
public void onDataSetChange() {
mRvTag.smoothScrollToPosition(mAdapter.getItemCount() - 1);
}
});
mRvTag.setLayoutManager(new TagLayoutManager.Builder()
.setBorderLeft(Utils.dp2px(this, 12))
.setBorderTop(Utils.dp2px(this, 8))
.setBorderRight(Utils.dp2px(this, 12))
.setBorderBottom(Utils.dp2px(this, 8))
.setBorderHor(Utils.dp2px(this, 8))
.setBorderVer(Utils.dp2px(this, 4))
.setMaxHeight(Utils.dp2px(this, 100))
.create());
mRvTag.setAdapter(mAdapter);
// avoid adapter call notifyItemChanged then the other item flashing
((SimpleItemAnimator)mRvTag.getItemAnimator()).setSupportsChangeAnimations(false);
}