Moses Aprico Moses Aprico - 1 year ago 142
Android Question

Inconsistent object placement inside CardView with RecyclerView


ADDITIONAL DETAILS: Strangely enough, it only gets buggy if there are only <=3 elements. More than that, because every element can be scrolled away, then the layout will "fix" itself upon reshowing.

ADDITIONAL DETAILS: Link to the demo video that showing the problem.

Youtube Video -

So below screenshot, was taken from the same run from an android studio.

In the screenshot, I have 2 exact same card view (with dummy data straight from the .xml, so, I assign no data from java file).

enter image description here
The problem

  1. If you guys look at the bottom right of each
    , there's a
    text view called "read more".

    Weirdly enough, even if they're identical, it's placed differently.
    Btw, it's actually 3 identical cards. On the first run, the top "read
    more" also incorrectly placed, but it auto-corrected itself when I
    completely scroll it down and back to the top.

  2. The second problem is the 5x4 dots on the top of the card. It's differently placed from what it's seen from the editor.

enter image description here

(The placement is accurate on editor)

Any idea how to handle this irregularity? Thanks.

Btw, I'm not sure if you guys need the code, but just in case, here it is on Pastebin (to shorten the post length).

Answer Source

Use match_parent for RecyclerView.

Fix like this:


If parent view's width is wrap_content, parent view's width can not be determined until child view's width is determed. I don't know the result of setting layout_width="wrap_content" for parent view and layout_width="match_parent" for child view. I guess the result may be wrong layout. In your layout, the same situation is happend. RecyclerView has layout_width="wrap_content" and CardView has layout_width="match_parent".

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download