Search in sources :

Example 11 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project SwipeRecyclerView by yanzhenjie.

the class DefaultActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_refresh_loadmore);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    ActionBar actionBar = getSupportActionBar();
    assert actionBar != null;
    actionBar.setDisplayHomeAsUpEnabled(true);
    mRefreshLayout = findViewById(R.id.refresh_layout);
    // 刷新监听。
    mRefreshLayout.setOnRefreshListener(mRefreshListener);
    mRecyclerView = findViewById(R.id.recycler_view);
    mRecyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    mRecyclerView.addItemDecoration(new DefaultItemDecoration(ContextCompat.getColor(this, R.color.divider_color)));
    // RecyclerView Item点击监听。
    mRecyclerView.setOnItemClickListener(mItemClickListener);
    // 使用默认的加载更多的View。
    mRecyclerView.useDefaultLoadMore();
    // 加载更多的监听。
    mRecyclerView.setLoadMoreListener(mLoadMoreListener);
    mAdapter = new MainAdapter(this);
    mRecyclerView.setAdapter(mAdapter);
    // 请求服务器加载数据。
    loadData();
}
Also used : MainAdapter(com.yanzhenjie.recyclerview.sample.adapter.MainAdapter) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) DefaultItemDecoration(com.yanzhenjie.recyclerview.widget.DefaultItemDecoration) ActionBar(androidx.appcompat.app.ActionBar) Toolbar(androidx.appcompat.widget.Toolbar)

Example 12 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project epoxy by airbnb.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    EpoxyRecyclerView recyclerView = (EpoxyRecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setLayoutManager(new GridLayoutManager(this, 2));
    recyclerView.setController(controller);
    if (savedInstanceState != null) {
        carousels = savedInstanceState.getParcelableArrayList(CAROUSEL_DATA_KEY);
    }
    initTouch(recyclerView);
    updateController();
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) EpoxyRecyclerView(com.airbnb.epoxy.EpoxyRecyclerView)

Example 13 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project epoxy by airbnb.

the class EpoxyItemSpacingDecorator method calculatePositionDetails.

private void calculatePositionDetails(RecyclerView parent, int position, LayoutManager layout) {
    int itemCount = parent.getAdapter().getItemCount();
    firstItem = position == 0;
    lastItem = position == itemCount - 1;
    horizontallyScrolling = layout.canScrollHorizontally();
    verticallyScrolling = layout.canScrollVertically();
    grid = layout instanceof GridLayoutManager;
    if (grid) {
        GridLayoutManager grid = (GridLayoutManager) layout;
        final SpanSizeLookup spanSizeLookup = grid.getSpanSizeLookup();
        int spanSize = spanSizeLookup.getSpanSize(position);
        int spanCount = grid.getSpanCount();
        int spanIndex = spanSizeLookup.getSpanIndex(position, spanCount);
        isFirstItemInRow = spanIndex == 0;
        fillsLastSpan = spanIndex + spanSize == spanCount;
        isInFirstRow = isInFirstRow(position, spanSizeLookup, spanCount);
        isInLastRow = !isInFirstRow && isInLastRow(position, itemCount, spanSizeLookup, spanCount);
    }
}
Also used : SpanSizeLookup(androidx.recyclerview.widget.GridLayoutManager.SpanSizeLookup) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager)

Example 14 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project Signal-Android by WhisperSystems.

the class PaymentsRecoveryPhraseFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    Toolbar toolbar = view.findViewById(R.id.payments_recovery_phrase_fragment_toolbar);
    RecyclerView recyclerView = view.findViewById(R.id.payments_recovery_phrase_fragment_recycler);
    TextView message = view.findViewById(R.id.payments_recovery_phrase_fragment_message);
    View next = view.findViewById(R.id.payments_recovery_phrase_fragment_next);
    View edit = view.findViewById(R.id.payments_recovery_phrase_fragment_edit);
    View copy = view.findViewById(R.id.payments_recovery_phrase_fragment_copy);
    GridLayoutManager gridLayoutManager = new GridLayoutManager(requireContext(), SPAN_COUNT);
    PaymentsRecoveryPhraseFragmentArgs args = PaymentsRecoveryPhraseFragmentArgs.fromBundle(requireArguments());
    final List<String> words;
    if (args.getWords() != null) {
        words = Arrays.asList(args.getWords());
        setUpForConfirmation(message, next, edit, copy, words);
    } else {
        Mnemonic mnemonic = SignalStore.paymentsValues().getPaymentsMnemonic();
        words = mnemonic.getWords();
        setUpForDisplay(message, next, edit, copy, words, args);
    }
    List<MnemonicPart> parts = Stream.of(words).mapIndexed(MnemonicPart::new).sorted(new MnemonicPartComparator(words.size(), SPAN_COUNT)).toList();
    MnemonicPartAdapter adapter = new MnemonicPartAdapter();
    recyclerView.setLayoutManager(gridLayoutManager);
    recyclerView.setAdapter(adapter);
    recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
    toolbar.setNavigationOnClickListener(v -> {
        if (args.getFinishOnConfirm()) {
            requireActivity().finish();
        } else {
            toolbar.setNavigationOnClickListener(t -> Navigation.findNavController(view).popBackStack(R.id.paymentsHome, false));
        }
    });
    adapter.submitList(parts);
}
Also used : View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Mnemonic(org.thoughtcrime.securesms.payments.Mnemonic) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) Toolbar(androidx.appcompat.widget.Toolbar)

Example 15 with GridLayoutManager

use of androidx.recyclerview.widget.GridLayoutManager in project boilerplate by koush.

the class GridRecyclerView method setNumColumns.

private void setNumColumns(Context context, int numColumns) {
    if (gridLayoutManager == null) {
        gridLayoutManager = new GridLayoutManager(context, numColumns);
        typeToSpan = new Hashtable<Integer, Integer>();
        gridLayoutManager.setSpanSizeLookup(spanSizeLookup = new GridLayoutManager.SpanSizeLookup() {

            @Override
            public int getSpanSize(int position) {
                int viewType = getAdapter().getItemViewType(position);
                Integer span = typeToSpan.get(viewType);
                if (span != null)
                    return span;
                ViewHolder vh = getAdapter().createViewHolder(GridRecyclerView.this, viewType);
                int foundSpan;
                if (vh instanceof SpanningViewHolder)
                    foundSpan = ((SpanningViewHolder) vh).getSpanSize(gridLayoutManager.getSpanCount());
                else
                    foundSpan = 1;
                typeToSpan.put(viewType, foundSpan);
                return foundSpan;
            }
        });
        setLayoutManager(gridLayoutManager);
    } else {
        gridLayoutManager.setSpanCount(numColumns);
    }
    typeToSpan.clear();
    spanSizeLookup.invalidateSpanIndexCache();
    requestLayout();
}
Also used : GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager)

Aggregations

GridLayoutManager (androidx.recyclerview.widget.GridLayoutManager)109 RecyclerView (androidx.recyclerview.widget.RecyclerView)57 View (android.view.View)44 TextView (android.widget.TextView)19 StaggeredGridLayoutManager (androidx.recyclerview.widget.StaggeredGridLayoutManager)14 ImageView (android.widget.ImageView)11 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)11 Toolbar (androidx.appcompat.widget.Toolbar)10 Nullable (androidx.annotation.Nullable)9 SmoothScrollGridLayoutManager (eu.davidea.flexibleadapter.common.SmoothScrollGridLayoutManager)7 ViewGroup (android.view.ViewGroup)6 SuppressLint (android.annotation.SuppressLint)5 Context (android.content.Context)5 NonNull (androidx.annotation.NonNull)5 ArrayList (java.util.ArrayList)5 RefreshingListenerAdapter (me.dkzwm.widget.srl.RefreshingListenerAdapter)5 List (java.util.List)4 Handler (android.os.Handler)3 FrameLayout (android.widget.FrameLayout)3 SwipeRefreshLayout (androidx.swiperefreshlayout.widget.SwipeRefreshLayout)3