simonebortolin / FlowLayoutManager

Android 3rd party library to make implementing a FlowLayoutManager
GNU General Public License v3.0
21 stars 11 forks source link

Ignore layout_margin #8

Closed yandroidUA closed 4 years ago

yandroidUA commented 4 years ago
<androidx.constraintlayout.widget.ConstraintLayout android:id="@+id/ingredientContainerView"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/background_rounded_black_empty"
    android:paddingStart="10dp"
    android:paddingEnd="10dp"
    android:paddingTop="4dp"
    android:paddingBottom="4dp"
    android:layout_margin="5dp"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <TextView android:id="@+id/ingredientNameView"
        android:fontFamily="@font/roboto_regular"
        android:textSize="14sp"
        android:textColor="@color/colorBlacker"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        tools:text="Сир"/>

</androidx.constraintlayout.widget.ConstraintLayout>

So each item looks like: item

But got: 1233

simonebortolin commented 4 years ago

I'm going to migrate to androidx shortly, and I'll investigate that bug as soon as I have a second. I hope to fix the bug as soon as possible, but I haven't touched this library in over two years. But I don't see any information about using FlowLayoutManager.

yandroidUA commented 4 years ago

That's how i'm using FlowLayoutManager in my project.

  1. Creating
    private val ingredientsFlowLayoutManager by lazy {
        val flowLayoutManager = FlowLayoutManager()
        flowLayoutManager.isAutoMeasureEnabled = true
        flowLayoutManager.setAlignment(Alignment.LEFT)
        flowLayoutManager
    }
  2. Setting
    private fun setupIngredients() {
        ingredientsRecyclerView?.layoutManager = ingredientsFlowLayoutManager
        ingredientsRecyclerView?.adapter = ingredientsAdapter
    }
simonebortolin commented 4 years ago

in the new version I do not see this problem, I suppose it was for an incompatibility between pre-androidX and androidX If you're still having problems, try forking and modifying the sample app and notify me.

simonebortolin commented 4 years ago

image image image

yandroidUA commented 4 years ago

I'm updated version to 1.8.0 and nothing changes, so I forked project and start experiment with it. Finally, i'm comment this line, inside in MainActivity:

    RecyclerView.ItemDecoration itemDecoration = new RecyclerView.ItemDecoration() {
        @Override
        public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
            super.getItemOffsets(outRect, view, parent, state);
//            outRect.set(5, 5, 5, 5);
        }
    };

But in XML each view has android:layout_margin="5dp", so they must not be so close to each other.

And it looks like:

123

If i'm adding ItemDecorationand overriding getItemOffsets all works fine.

simonebortolin commented 4 years ago

Sorry, I didn't understand if you want the tags close together or far apart? Ok, so it's not a compatibility problem between androidx and legacy stuff, but a hardcoded value problem in the code, as I think you can imagine I didn't write this library, but I based it on existing code. Can you commit your changes?

simonebortolin commented 4 years ago

in fact it was a iusse in the original repo https://github.com/xiaofeng-han/AndroidLibs/issues/21

yandroidUA commented 4 years ago

Yeap, i just want some space between items, like that:

4

Yeap, seems that it's the same problem in #xiaofeng-han#21. So closing the issue, because root of problem not in your code. Thanks for your attention.

simonebortolin commented 4 years ago

The original code hasn't been updated for years, I was the last code maintainer.