Java源码示例:android.support.v4.widget.AutoScrollHelper

示例1
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();
    }
 
示例2
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);
}
 
示例3
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);
}
 
示例4
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);
}
 
示例5
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);
}
 
示例6
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;
}
 
示例7
private void init() {
    scrollView = (ScrollView) findViewById(R.id.scroll_view);
    AutoScrollHelper autoScrollHelper = new ScrollViewAutoScrollHelper(scrollView);
    autoScrollHelper.setEnabled(true);
    scrollView.setOnTouchListener(autoScrollHelper);
}