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);
}
}
}
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;
}
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;
}
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);
}
});
}
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;
}
Aggregations