leshchenko/CircularLayoutManager

Circle not centered

Closed this issue ยท 10 comments

I am having an issue with the Recyclerview items not being centered correctly in the circle. Not sure if I am doing something wrong here.

See outer circle
IMG_20191009_161428

My layout file of outer circle:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="250dp"
    android:layout_height="350dp">

    <View
        android:id="@+id/sidebarBackground"
        android:layout_width="350dp"
        android:layout_height="match_parent"
        android:layout_marginStart="-150dp"
        android:background="@drawable/circle"
        android:backgroundTint="#DFDFDF" />

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerviewSources"
        android:layout_width="350dp"
        android:layout_height="match_parent"
        android:layout_marginStart="-150dp" />

</RelativeLayout>

CircularRecyclerLayoutManager

CircularRecyclerLayoutManager layoutManager = new CircularRecyclerLayoutManager(5,
                45,
                200,
                0,
                false,
                180,
                true);

@Glennmen Looks strange. Thanks, I'll take a look.

@leshchenko Is this part correct?

val xCoordinate = (radius * sinAngle(angle)) + centerPoint.x
val yCoordinate = (radius * cosAngle(angle)) + centerPoint.y

I did some searching and it seems that your x & y calculations should be switched:
https://math.stackexchange.com/a/854287
image

@Glennmen Please try new version.

I am going to pull this repo and try to investigate myself for a correct solution, could you reopen this issue?

Btw I haven't tested the new version, will do that first but seeing that cos/sin isn't correct this should still be fixed.

@Glennmen Fixed in 1.1.5.

@leshchenko Using v1.1.5 and still having the same issue (not centered).

@leshchenko I made a branch with changes to the app sample so you can reproduce the bug I am having: https://github.com/Glennmen/CircularLayoutManager/tree/reproduce-off-center

I will try to look into it myself and let you know if I find anything.

I think the issue is with this line:

itemWidth is being calculated on other values and not based on the actual child item size. Because of this the items are being added with a wrong size and looks off-centered.

I added a background color to the view to visualise this.
IMG_20191010_145252

@Glennmen Item size calculates depends on layout manager settings, it's need to fit all items in a circle radius and have some free space between items. Could you please create sample project and push it on Github? I think there is issue with xml layout.

Items not being centered in the item view was a mistake from my end ๐Ÿคฆโ€โ™‚๏ธ
Item view size being bigger than I wanted is specific to my project I think, so it can remain like it is now. I was able to find a workaround so that I can pass touches outside my item (but still inside the item view) to the window behind it.

I will close this issue, thanks for the support.