android.support.v4.widget.AutoScrollHelper Java Examples
The following examples show how to use
android.support.v4.widget.AutoScrollHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ListViewActivity.java From Rocko-Android-Demos with Apache License 2.0 | 6 votes |
private void init() { listView = (ListView) findViewById(R.id.list_view); String[] strs = getData(100); List<Map<String, Object>> list = new ArrayList<>(); for (String str : strs) { Map<String, Object> map = new HashMap<>(); map.put("text", str); list.add(map); } SimpleAdapter adapter = new SimpleAdapter(this, list, R.layout.item_simple, new String[]{"text"}, new int[]{R.id.text_view}); listView.setAdapter(adapter); AutoScrollHelper autoScrollHelper = new ListViewAutoScrollHelper(listView); listView.setOnTouchListener(autoScrollHelper); autoScrollHelper.setEnabled(true); // autoScrollHelper.setActivationDelay(3000); // autoScrollHelper.setRampDownDuration(3000); Toast.makeText(this, "长按上或下边缘", Toast.LENGTH_SHORT).show(); }
Example #2
Source File: ListBuddiesLayout.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private void setScrollHelpers() { mScrollHelper = new ListBuddiesAutoScrollHelper(mListViewLeft) { @Override public void scrollTargetBy(int deltaX, int deltaY) { mListViewLeft.smoothScrollBy(mSpeedLeft, 0); mListViewRight.smoothScrollBy(mSpeedRight, 0); } @Override public boolean canTargetScrollHorizontally(int i) { return false; } @Override public boolean canTargetScrollVertically(int i) { return true; } }; mScrollHelper.setEnabled(isEnable()); mScrollHelper.setEdgeType(AutoScrollHelper.EDGE_TYPE_OUTSIDE); }
Example #3
Source File: ListBuddiesLayout.java From UltimateAndroid with Apache License 2.0 | 6 votes |
private void setScrollHelpers() { mScrollHelper = new ListBuddiesAutoScrollHelper(mListViewLeft) { @Override public void scrollTargetBy(int deltaX, int deltaY) { mListViewLeft.smoothScrollBy(mSpeedLeft, 0); mListViewRight.smoothScrollBy(mSpeedRight, 0); } @Override public boolean canTargetScrollHorizontally(int i) { return false; } @Override public boolean canTargetScrollVertically(int i) { return true; } }; mScrollHelper.setEnabled(isEnable()); mScrollHelper.setEdgeType(AutoScrollHelper.EDGE_TYPE_OUTSIDE); }
Example #4
Source File: ListBuddiesLayout.java From ListBuddies with Apache License 2.0 | 6 votes |
private void setScrollHelpers() { mScrollHelper = new ListBuddiesAutoScrollHelper(mListViewLeft) { @Override public void scrollTargetBy(int deltaX, int deltaY) { mListViewLeft.smoothScrollBy(mSpeedLeft, 0); mListViewRight.smoothScrollBy(mSpeedRight, 0); } @Override public boolean canTargetScrollHorizontally(int i) { return false; } @Override public boolean canTargetScrollVertically(int i) { return true; } }; mScrollHelper.setEnabled(isEnable()); mScrollHelper.setEdgeType(AutoScrollHelper.EDGE_TYPE_OUTSIDE); }
Example #5
Source File: RecyclerViewActivity.java From Rocko-Android-Demos with Apache License 2.0 | 5 votes |
private void init() { recyclerView = (RecyclerView) findViewById(R.id.recyler_view); linearLayoutManager = new LinearLayoutManager(this); linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL); staggeredGridLayoutManager = new StaggeredGridLayoutManager(3, StaggeredGridLayoutManager.VERTICAL); recyclerView.setLayoutManager(linearLayoutManager); recyclerView.setAdapter(new SimpleRecylerViewAdapter(this, getData(100))); AutoScrollHelper autoScrollHelper = new RecyclerViewAutoScrollHelper(recyclerView); autoScrollHelper.setEnabled(true); recyclerView.setOnTouchListener(autoScrollHelper); }
Example #6
Source File: ViewPager.java From letv with Apache License 2.0 | 4 votes |
private void calculatePageOffsets(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) { float offset; int pos; ItemInfo ii; int N = this.mAdapter.getCount(); int width = getClientWidth(); float marginOffset = width > 0 ? ((float) this.mPageMargin) / ((float) width) : 0.0f; if (oldCurInfo != null) { int oldCurPosition = oldCurInfo.position; int itemIndex; if (oldCurPosition < curItem.position) { itemIndex = 0; offset = (oldCurInfo.offset + oldCurInfo.widthFactor) + marginOffset; pos = oldCurPosition + 1; while (pos <= curItem.position && itemIndex < this.mItems.size()) { ii = (ItemInfo) this.mItems.get(itemIndex); while (pos > ii.position && itemIndex < this.mItems.size() - 1) { itemIndex++; ii = (ItemInfo) this.mItems.get(itemIndex); } while (pos < ii.position) { offset += this.mAdapter.getPageWidth(pos) + marginOffset; pos++; } ii.offset = offset; offset += ii.widthFactor + marginOffset; pos++; } } else if (oldCurPosition > curItem.position) { itemIndex = this.mItems.size() - 1; offset = oldCurInfo.offset; pos = oldCurPosition - 1; while (pos >= curItem.position && itemIndex >= 0) { ii = (ItemInfo) this.mItems.get(itemIndex); while (pos < ii.position && itemIndex > 0) { itemIndex--; ii = (ItemInfo) this.mItems.get(itemIndex); } while (pos > ii.position) { offset -= this.mAdapter.getPageWidth(pos) + marginOffset; pos--; } offset -= ii.widthFactor + marginOffset; ii.offset = offset; pos--; } } } int itemCount = this.mItems.size(); offset = curItem.offset; pos = curItem.position - 1; this.mFirstOffset = curItem.position == 0 ? curItem.offset : -3.4028235E38f; this.mLastOffset = curItem.position == N + -1 ? (curItem.offset + curItem.widthFactor) - 1.0f : AutoScrollHelper.NO_MAX; int i = curIndex - 1; while (i >= 0) { ii = (ItemInfo) this.mItems.get(i); while (pos > ii.position) { offset -= this.mAdapter.getPageWidth(pos) + marginOffset; pos--; } offset -= ii.widthFactor + marginOffset; ii.offset = offset; if (ii.position == 0) { this.mFirstOffset = offset; } i--; pos--; } offset = (curItem.offset + curItem.widthFactor) + marginOffset; pos = curItem.position + 1; i = curIndex + 1; while (i < itemCount) { ii = (ItemInfo) this.mItems.get(i); while (pos < ii.position) { offset += this.mAdapter.getPageWidth(pos) + marginOffset; pos++; } if (ii.position == N - 1) { this.mLastOffset = (ii.widthFactor + offset) - 1.0f; } ii.offset = offset; offset += ii.widthFactor + marginOffset; i++; pos++; } this.mNeedCalculatePageOffsets = false; }
Example #7
Source File: ScrollViewActivity.java From Rocko-Android-Demos with Apache License 2.0 | 4 votes |
private void init() { scrollView = (ScrollView) findViewById(R.id.scroll_view); AutoScrollHelper autoScrollHelper = new ScrollViewAutoScrollHelper(scrollView); autoScrollHelper.setEnabled(true); scrollView.setOnTouchListener(autoScrollHelper); }