use of androidx.recyclerview.widget.LinearLayoutManager in project FlexibleAdapter by davideas.
the class FlexibleLayoutManager method findFirstCompletelyVisibleItemPosition.
/**
* Helper method to find the adapter position of the <b>first completely</b> visible view
* [for each span], no matter which Layout is.
*
* @return the adapter position of the <b>first fully</b> visible item or {@code RecyclerView.NO_POSITION}
* if there aren't any visible items.
* @see #findFirstVisibleItemPosition()
* @since 5.0.0-b8
*/
@Override
public int findFirstCompletelyVisibleItemPosition() {
RecyclerView.LayoutManager layoutManager = getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGLM = (StaggeredGridLayoutManager) layoutManager;
int position = staggeredGLM.findFirstCompletelyVisibleItemPositions(null)[0];
for (int i = 1; i < getSpanCount(); i++) {
int nextPosition = staggeredGLM.findFirstCompletelyVisibleItemPositions(null)[i];
if (nextPosition < position) {
position = nextPosition;
}
}
return position;
} else {
return ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition();
}
}
use of androidx.recyclerview.widget.LinearLayoutManager in project CircleIndicator by ongakuer.
the class RecyclerViewFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
mAdapter = new SampleRecyclerAdapter(5);
RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(mAdapter);
PagerSnapHelper pagerSnapHelper = new PagerSnapHelper();
pagerSnapHelper.attachToRecyclerView(recyclerView);
// CircleIndicator2 for RecyclerView
CircleIndicator2 indicator = view.findViewById(R.id.indicator);
indicator.attachToRecyclerView(recyclerView, pagerSnapHelper);
// Scroll To Position
layoutManager.scrollToPosition(2);
// Observe Data Change
mAdapter.registerAdapterDataObserver(indicator.getAdapterDataObserver());
view.findViewById(R.id.add).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAdapter.add();
}
});
view.findViewById(R.id.remove).setOnClickListener(v -> {
mAdapter.remove();
});
}
use of androidx.recyclerview.widget.LinearLayoutManager in project FlexibleAdapter by davideas.
the class FlexibleLayoutManager method findLastCompletelyVisibleItemPosition.
/**
* Helper method to find the adapter position of the <b>last completely</b> visible view
* [for each span], no matter which Layout is.
*
* @return the adapter position of the <b>last fully</b> visible item or {@code RecyclerView.NO_POSITION}
* if there aren't any visible items.
* @see #findLastVisibleItemPosition()
* @since 5.0.0-b8
*/
@Override
public int findLastCompletelyVisibleItemPosition() {
RecyclerView.LayoutManager layoutManager = getLayoutManager();
if (layoutManager instanceof StaggeredGridLayoutManager) {
StaggeredGridLayoutManager staggeredGLM = (StaggeredGridLayoutManager) layoutManager;
int position = staggeredGLM.findLastCompletelyVisibleItemPositions(null)[0];
for (int i = 1; i < getSpanCount(); i++) {
int nextPosition = staggeredGLM.findLastCompletelyVisibleItemPositions(null)[i];
if (nextPosition > position) {
position = nextPosition;
}
}
return position;
} else {
return ((LinearLayoutManager) layoutManager).findLastCompletelyVisibleItemPosition();
}
}
use of androidx.recyclerview.widget.LinearLayoutManager in project RxBinding by JakeWharton.
the class RxRecyclerViewTestActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
recyclerView = new RecyclerView(this);
recyclerView.setId(android.R.id.primary);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
setContentView(recyclerView);
}
use of androidx.recyclerview.widget.LinearLayoutManager in project simple-stack by Zhuinden.
the class WordListFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
final Backstack backstack = Navigator.getBackstack(requireContext());
dataProvider = backstack.lookupService(DataProvider.class.getName());
actionHandler = backstack.lookupService(ActionHandler.class.getName());
controllerEvents = backstack.lookupService("WordEventEmitter");
RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter);
view.findViewById(R.id.buttonGoToAddNewWord).setOnClickListener(v -> actionHandler.onAddNewWordClicked());
dataProvider.getWordList().observe(getViewLifecycleOwner(), words -> adapter.updateWords(words));
}
Aggregations