Search in sources :

Example 81 with LinearLayoutManager

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();
    }
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 82 with LinearLayoutManager

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();
    });
}
Also used : CircleIndicator2(me.relex.circleindicator.CircleIndicator2) SampleRecyclerAdapter(me.relex.circleindicator.sample.SampleRecyclerAdapter) PagerSnapHelper(androidx.recyclerview.widget.PagerSnapHelper) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 83 with LinearLayoutManager

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();
    }
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) StaggeredGridLayoutManager(androidx.recyclerview.widget.StaggeredGridLayoutManager) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 84 with LinearLayoutManager

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);
}
Also used : RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Example 85 with LinearLayoutManager

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));
}
Also used : Backstack(com.zhuinden.simplestack.Backstack) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)470 RecyclerView (androidx.recyclerview.widget.RecyclerView)281 View (android.view.View)183 TextView (android.widget.TextView)65 ArrayList (java.util.ArrayList)37 Nullable (androidx.annotation.Nullable)33 Bundle (android.os.Bundle)32 Toolbar (androidx.appcompat.widget.Toolbar)32 Intent (android.content.Intent)30 ImageView (android.widget.ImageView)27 List (java.util.List)24 Test (org.junit.Test)24 Context (android.content.Context)23 NonNull (androidx.annotation.NonNull)23 ViewGroup (android.view.ViewGroup)22 AlertDialog (androidx.appcompat.app.AlertDialog)21 ContextualCard (com.android.settings.homepage.contextualcards.ContextualCard)20 LayoutInflater (android.view.LayoutInflater)18 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)16 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)16