當前位置: 首頁>>代碼示例>>Java>>正文


Java LinearSmoothScroller.setTargetPosition方法代碼示例

本文整理匯總了Java中android.support.v7.widget.LinearSmoothScroller.setTargetPosition方法的典型用法代碼示例。如果您正苦於以下問題:Java LinearSmoothScroller.setTargetPosition方法的具體用法?Java LinearSmoothScroller.setTargetPosition怎麽用?Java LinearSmoothScroller.setTargetPosition使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.support.v7.widget.LinearSmoothScroller的用法示例。


在下文中一共展示了LinearSmoothScroller.setTargetPosition方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(final RecyclerView recyclerView, RecyclerView.State state, int position) {
   final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
      @Override
      public int calculateDyToMakeVisible(View view, int snapPreference) {
         final RecyclerView.LayoutManager layoutManager = getLayoutManager();
         if (layoutManager == null || !layoutManager.canScrollVertically()) {
            return 0;
         }

         final int adapterPosition = getPosition(view);
         final int topOffset = getPositionSectionHeaderHeight(adapterPosition);
         final int top = layoutManager.getDecoratedTop(view);
         final int bottom = layoutManager.getDecoratedBottom(view);
         final int start = layoutManager.getPaddingTop() + topOffset;
         final int end = layoutManager.getHeight() - layoutManager.getPaddingBottom();
         return calculateDtToFit(top, bottom, start, end, snapPreference);
      }
   };
   linearSmoothScroller.setTargetPosition(position);
   startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:Codewaves,項目名稱:Sticky-Header-Grid,代碼行數:23,代碼來源:StickyHeaderGridLayoutManager.java

示例2: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }

        @Nullable
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return WheelPickerLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }
    };

    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:devilist,項目名稱:RecyclerWheelPicker,代碼行數:19,代碼來源:WheelPickerLayoutManager.java

示例3: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    //
    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext){
        @Nullable
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return ScrollerLinearLayoutManager.this.computeScrollVectorForPosition
                    (targetPosition);
        }

        //1 pixel -> 0.05 ms
        //1000 pixel -> x=50 ms to go over the height of the screen
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return 0.05f;
            //return x /displayMetrics.densityDpi;
        }
    };
    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:cahergil,項目名稱:Farmacias,代碼行數:23,代碼來源:ScrollerLinearLayoutManager.java

示例4: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int
        position) {

    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView
            .getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition
                    (targetPosition);
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:GcsSloop,項目名稱:diycode,代碼行數:23,代碼來源:SpeedyLinearLayoutManager.java

示例5: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    LinearSmoothScroller linearSmoothScroller =
            new LinearSmoothScroller(recyclerView.getContext()) {

                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    if (scrollSpeed != null) {
                        float speed = scrollSpeed.calculateSpeedPerPixel(super.calculateSpeedPerPixel(displayMetrics));
                        scrollSpeed = null;
                        return speed;
                    }
                    return super.calculateSpeedPerPixel(displayMetrics);
                }

                @Nullable
                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return super.computeScrollVectorForPosition(targetPosition);
                }
            };
    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:AllanWang,項目名稱:Capsule,代碼行數:25,代碼來源:SGridLayoutManager.java

示例6: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    LinearSmoothScroller linearSmoothScroller =
            new LinearSmoothScroller(recyclerView.getContext()) {

                @Override
                protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
                    if (scrollSpeed != null) {
                        float speed = scrollSpeed.calculateSpeedPerPixel(super.calculateSpeedPerPixel(displayMetrics));
                        scrollSpeed = null;
                        return speed;
                    }
                    return super.calculateSpeedPerPixel(displayMetrics);
                }

                @Nullable
                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return SLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
                }
            };
    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:AllanWang,項目名稱:Capsule,代碼行數:25,代碼來源:SLinearLayoutManager.java

示例7: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {

    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {

        //This controls the direction in which smoothScroll looks
        //for your view
        @Override
        public PointF computeScrollVectorForPosition
        (int targetPosition) {
            return CustomLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        //This returns the milliseconds it takes to
        //scroll one pixel.
        @Override
        protected float calculateSpeedPerPixel (DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH/displayMetrics.densityDpi;
        }
    };

    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:Old-Geek,項目名稱:Radio2,代碼行數:25,代碼來源:CustomLayoutManager.java

示例8: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {

    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return CustomLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    try {
        startSmoothScroll(linearSmoothScroller);
    } catch (IllegalArgumentException e) {
        // couldn't scroll for some reason, just ignore
    }
}
 
開發者ID:NightscoutFoundation,項目名稱:xDrip,代碼行數:24,代碼來源:ActivityWithRecycler.java

示例9: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {

    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {

        //This controls the direction in which smoothScroll looks
        //for your view
        @Override
        public PointF computeScrollVectorForPosition
        (int targetPosition) {
            return CustomGridLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        //This returns the milliseconds it takes to
        //scroll one pixel.
        @Override
        protected float calculateSpeedPerPixel (DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH/displayMetrics.densityDpi;
        }
    };

    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:Old-Geek,項目名稱:Musique,代碼行數:25,代碼來源:CustomGridLayoutManager.java

示例10: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {

    if (position < 0) {
        return;
    }

    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:toshiapp,項目名稱:toshi-android-client,代碼行數:24,代碼來源:SpeedyLinearLayoutManager.java

示例11: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    final LinearSmoothScroller linearSmoothScroller =
            new LinearSmoothScroller(recyclerView.getContext()) {

                // I want a behavior where the scrolling always snaps to the beginning of
                // the list. Snapping to end is also trivial given the default implementation.
                // If you need a different behavior, you may need to override more
                // of the LinearSmoothScrolling methods.
                protected int getHorizontalSnapPreference() {
                    return SNAP_TO_START;
                }

                protected int getVerticalSnapPreference() {
                    return SNAP_TO_START;
                }

                @Override
                public PointF computeScrollVectorForPosition(int targetPosition) {
                    return SnappyLinearLayoutManager.this
                            .computeScrollVectorForPosition(targetPosition);
                }
            };
    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:Luorrak,項目名稱:Ouroboros,代碼行數:27,代碼來源:SnappyLinearLayoutManager.java

示例12: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, final int position) {
    super.smoothScrollToPosition(recyclerView, state, position);

    LinearSmoothScroller smoothScroller = new LinearSmoothScroller(mContext) {

        //This controls the direction in which smoothScroll looks for your view
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return new PointF(0, 1);
        }

        //This returns the milliseconds it takes to scroll one pixel.
        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    smoothScroller.setTargetPosition(position);
    startSmoothScroll(smoothScroller);
}
 
開發者ID:moezbhatti,項目名稱:qksms,代碼行數:23,代碼來源:SmoothLinearLayoutManager.java

示例13: smoothScrollToPositionWithAlignment

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
public void smoothScrollToPositionWithAlignment(Context context, int position, final int scrollAlignment) {
    if (!isAttachedToWindow()) {
        // NOTE: startSmoothScroll() references mRecyclerView and it will crash when RecyclerView
        // is not attached to LayoutManager.
        scrollToPositionWithAlignment(position, scrollAlignment);
        return;
    }
    LinearSmoothScroller linearSmoothScroller = new CenterAwareLinearSmoothScroller(context, scrollAlignment) {
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            prepareLayoutProvider();
            Point targetScrollOffset = calculateScrollOffsetToShowPositionIfPossible(targetPosition, scrollAlignment);
            if (targetScrollOffset == null) return null;
            normalizeScrollOffset(targetScrollOffset);
            return ScrollHelper.calculateUnitVectorFromPoints(mCurrentScrollOffset, targetScrollOffset);
        }
    };
    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:ypresto,項目名稱:RecyclerView-AbsoluteLayoutManager,代碼行數:21,代碼來源:AbsoluteLayoutManager.java

示例14: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    final LinearSmoothScroller linearSmoothScroller = new LinearSmoothScroller(recyclerView.getContext()) {

        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            return SpeedyLinearLayoutManager.this.computeScrollVectorForPosition(targetPosition);
        }

        @Override
        protected float calculateSpeedPerPixel(DisplayMetrics displayMetrics) {
            return MILLISECONDS_PER_INCH / displayMetrics.densityDpi;
        }
    };

    linearSmoothScroller.setTargetPosition(position);
    startSmoothScroll(linearSmoothScroller);
}
 
開發者ID:particle-iot,項目名稱:photon-tinker-android,代碼行數:19,代碼來源:EventsFragment.java

示例15: smoothScrollToPosition

import android.support.v7.widget.LinearSmoothScroller; //導入方法依賴的package包/類
@Override
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
    position = Math.max(position, 0);
    position = Math.min(position, self.getItemCount());

    /*
     * LinearSmoothScroller's default behavior is to scroll the contents until
     * the child is fully visible. It will snap to the top-left or bottom-right
     * of the parent depending on whether the direction of travel was positive
     * or negative.
     */
    LinearSmoothScroller scroller = new LinearSmoothScroller(recyclerView.getContext()) {
        /*
         * LinearSmoothScroller, at a minimum, just need to know the vector
         * (x/y distance) to travel in order to get from the current positioning
         * to the target.
         */
        @Override
        public PointF computeScrollVectorForPosition(int targetPosition) {
            int oldScrollX = self.getState().scrolledX;
            int oldScrollY = self.getState().scrolledY;

            self.getState().scrolledX = self.getState().itemsFrames.get(targetPosition).left;
            self.getState().scrolledY = self.getState().itemsFrames.get(targetPosition).top;
            self.fixScrollOffset();

            int newScrollX = self.getState().scrolledX;
            int newScrollY = self.getState().scrolledY;

            self.getState().scrolledX = oldScrollX;
            self.getState().scrolledY = oldScrollY;

            return new PointF(newScrollX - oldScrollX, newScrollY - oldScrollY);
        }
    };
    scroller.setTargetPosition(position);
    self.startSmoothScroll(scroller);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:39,代碼來源:CustomLayoutManager.java


注:本文中的android.support.v7.widget.LinearSmoothScroller.setTargetPosition方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。