question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Help with center divider in GridLayout

See original GitHub issue

I’m trying to create a two column layout with dividers between the items, but what I’ve tried doesn’t work.

Here’s how I’m setting up the layout:

mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), COLUMN_COUNT));

Here’s how I’m setting the divider:

mRecyclerView.addItemDecoration(new FlexibleItemDecoration(getActivity())
        .withDivider(R.drawable.divider)
        .addItemViewType(R.layout.item_category_button,2,1,2,1)
        .withEdge(true)
        .withDrawOver(true));

With the above code, I see a center line, but it’s white and not the color as specified in the divider drawable. (I grabbed that divider drawable from the sample app.)

I’ve read the wiki and cloned the project so I can work directly with the example app, but I’m unable to create the center divider I need. From what I’m seeing, it appears the divider only applies to the top and bottom, not the left and right.

NOTE: If I use a left and right width of just 1 in the above code, I don’t even see the white center line.

Thanks for your library and I appreciate any help!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
NightSkyDevcommented, Feb 5, 2018

Try to override the logic in this method

I created a new ItemDecoration class and replaced the draw method and it worked great!

Maybe we can add a setting to draw in both orientation.

From reading the Wiki, I thought that’s what the left/right edge settings were for, but I guess they don’t apply to the item decoration.

Anyway, your suggestion worked so I’ll close this issue. Thanks again for the help!

0reactions
NightSkyDevcommented, Feb 5, 2018

android:background=“?android:selectableItemBackground”

Yes, that creates the button look I need for multiple columns and multiple rows.

Read more comments on GitHub >

github_iconTop Results From Across the Web

android GridLayout divider row - Stack Overflow
I'm trying to implement a tabular layout that has a header and a bunch of rows underneath it. I've chosen the GridLayout (android.support.v7....
Read more >
GridLayout | Android Developers
Fields. BASELINE; BOTTOM; CENTER; END; FILL; LEFT; RIGHT; START; TOP. Public constructors. GridLayout; GridLayout; GridLayout; GridLayout. Public methods.
Read more >
Grid layout using line-based placement - CSS - MDN Web Docs
In the article covering the basic concepts of grid layout, we started to look at how to position items on a grid using...
Read more >
Arrange Fields Using Grid Control - Business Central
Fields in a FastTab are arranged automatically. Use Grid control to manually set up rows, columns, span fields across, and show or hide ......
Read more >
SwiftUI Grid - The complete Guide - Sarunw
A Grid view arranges child views in rows and columns. This table-like structure makes a layout that is hard to do in vertical...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found