Search in sources :

Example 21 with ObservableRecyclerView

use of com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView in project Android-ObservableScrollView by ksoichiro.

the class FlexibleSpaceWithImageRecyclerViewFragment method setScrollY.

@Override
public void setScrollY(int scrollY, int threshold) {
    View view = getView();
    if (view == null) {
        return;
    }
    ObservableRecyclerView recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll);
    if (recyclerView == null) {
        return;
    }
    View firstVisibleChild = recyclerView.getChildAt(0);
    if (firstVisibleChild != null) {
        int offset = scrollY;
        int position = 0;
        if (threshold < scrollY) {
            int baseHeight = firstVisibleChild.getHeight();
            position = scrollY / baseHeight;
            offset = scrollY % baseHeight;
        }
        RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
        if (lm != null && lm instanceof LinearLayoutManager) {
            ((LinearLayoutManager) lm).scrollToPositionWithOffset(position, -offset);
        }
    }
}
Also used : ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) View(android.view.View)

Example 22 with ObservableRecyclerView

use of com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView in project Android-ObservableScrollView by ksoichiro.

the class FlexibleSpaceWithImageRecyclerViewFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_flexiblespacewithimagerecyclerview, container, false);
    final ObservableRecyclerView recyclerView = (ObservableRecyclerView) view.findViewById(R.id.scroll);
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerView.setHasFixedSize(false);
    final View headerView = LayoutInflater.from(getActivity()).inflate(R.layout.recycler_header, null);
    final int flexibleSpaceImageHeight = getResources().getDimensionPixelSize(R.dimen.flexible_space_image_height);
    headerView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, flexibleSpaceImageHeight));
    setDummyDataWithHeader(recyclerView, headerView);
    // TouchInterceptionViewGroup should be a parent view other than ViewPager.
    // This is a workaround for the issue #117:
    // https://github.com/ksoichiro/Android-ObservableScrollView/issues/117
    recyclerView.setTouchInterceptionViewGroup((ViewGroup) view.findViewById(R.id.fragment_root));
    // Scroll to the specified offset after layout
    Bundle args = getArguments();
    if (args != null && args.containsKey(ARG_SCROLL_Y)) {
        final int scrollY = args.getInt(ARG_SCROLL_Y, 0);
        ScrollUtils.addOnGlobalLayoutListener(recyclerView, new Runnable() {

            @Override
            public void run() {
                int offset = scrollY % flexibleSpaceImageHeight;
                RecyclerView.LayoutManager lm = recyclerView.getLayoutManager();
                if (lm != null && lm instanceof LinearLayoutManager) {
                    ((LinearLayoutManager) lm).scrollToPositionWithOffset(0, -offset);
                }
            }
        });
        updateFlexibleSpace(scrollY, view);
    } else {
        updateFlexibleSpace(0, view);
    }
    recyclerView.setScrollViewCallbacks(this);
    return view;
}
Also used : ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) RecyclerView(android.support.v7.widget.RecyclerView) ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) View(android.view.View) LinearLayout(android.widget.LinearLayout)

Example 23 with ObservableRecyclerView

use of com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView in project Android-ObservableScrollView by ksoichiro.

the class FillGap3RecyclerViewActivity method createScrollable.

@Override
protected ObservableRecyclerView createScrollable() {
    ObservableRecyclerView recyclerView = (ObservableRecyclerView) findViewById(R.id.scroll);
    recyclerView.setScrollViewCallbacks(this);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(true);
    setDummyDataFew(recyclerView);
    return recyclerView;
}
Also used : ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Example 24 with ObservableRecyclerView

use of com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView in project Android-ObservableScrollView by ksoichiro.

the class RecyclerViewScrollFromBottomActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final ObservableRecyclerView scrollable = (ObservableRecyclerView) findViewById(R.id.scrollable);
    ScrollUtils.addOnGlobalLayoutListener(scrollable, new Runnable() {

        @Override
        public void run() {
            int count = scrollable.getAdapter().getItemCount() - 1;
            int position = count == 0 ? 1 : count > 0 ? count : 0;
            scrollable.scrollToPosition(position);
        }
    });
}
Also used : ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView)

Example 25 with ObservableRecyclerView

use of com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView in project Android-ObservableScrollView by ksoichiro.

the class ToolbarControlRecyclerViewActivity method createScrollable.

@Override
protected ObservableRecyclerView createScrollable() {
    ObservableRecyclerView recyclerView = (ObservableRecyclerView) findViewById(R.id.scrollable);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(true);
    setDummyData(recyclerView);
    return recyclerView;
}
Also used : ObservableRecyclerView(com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager)

Aggregations

ObservableRecyclerView (com.github.ksoichiro.android.observablescrollview.ObservableRecyclerView)27 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)23 View (android.view.View)16 ObservableScrollViewCallbacks (com.github.ksoichiro.android.observablescrollview.ObservableScrollViewCallbacks)6 Activity (android.app.Activity)5 TextView (android.widget.TextView)5 Bundle (android.os.Bundle)4 RecyclerView (android.support.v7.widget.RecyclerView)4 Fragment (android.support.v4.app.Fragment)3 ImageView (android.widget.ImageView)3 ArrayList (java.util.ArrayList)3 SimpleDraweeView (com.facebook.drawee.view.SimpleDraweeView)2 ArtistInfoFragment (com.wm.remusic.fragmentnet.ArtistInfoFragment)2 ArtistInfoMusicFragment (com.wm.remusic.fragmentnet.ArtistInfoMusicFragment)2 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 ViewGroup (android.view.ViewGroup)1 ViewTreeObserver (android.view.ViewTreeObserver)1 LinearLayout (android.widget.LinearLayout)1 TintImageView (com.bilibili.magicasakura.widgets.TintImageView)1