3

How can I create circular list for round watch as in android wear 2.0 ?.

Like this:

enter image description here

Circular list is seen in android wear app launcher.

LaurentY
  • 7,495
  • 3
  • 37
  • 55
adhiti
  • 39
  • 1
  • 2
  • Please check this blog article - http://android-developers.blogspot.com/2016/04/build-beautifully-for-android-wear.html – Sufian Jul 19 '16 at 09:23
  • This will not help had checked. BoxInsetLayout sets a square inset but here items are aligned to edge (even scrollbar is circular) – adhiti Jul 20 '16 at 04:40

2 Answers2

3

First of all you need to replace your ListView with a WearableRecyclerView. It can be used like a normal ListView. But make sure, you import the right one from android.support.wear.widget. DON'T use the one from android.support.wearable.view. This one should be crossed out, so it won't take you long to check if you're using the right one. If there's just one WearableRecyclerViewto choose from, make sure to add compile 'com.android.support:wear:27.0.0' to the dependencies in your build.gradle (wear) file. Also make sure that you're using <android.support.wear.widget.WearableRecyclerView/> in your activity.xml. If you just want a circular ListView without any custom item-scaling, just call this in your onLayoutInflated() method:

your_recyclerview.setEdgeItemsCenteringEnabled(true);
your_recyclerview.setLayoutManager(new WearableLinearLayoutManager(your_activity_context));

If you want to make items scaling up when they get closer to the center of your screen, things get a little more complicated.

First: paste this in your Activity.java:

private class CustomScrollingLayoutCallback extends WearableLinearLayoutManager.LayoutCallback {

        private static final float MAX_ICON_PROGRESS = 2F;

        @Override
        public void onLayoutFinished(View child, RecyclerView parent) {

            float centerOffset = ((float) child.getHeight() / 2.0f) / (float) parent.getHeight();
            float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;

            float progresstoCenter = (float) Math.sin(yRelativeToCenterOffset * Math.PI);

            float mProgressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);

            mProgressToCenter = Math.min(mProgressToCenter, MAX_ICON_PROGRESS);

            child.setScaleX(1 - mProgressToCenter);
            child.setScaleY(1 - mProgressToCenter);
            child.setX(+(1 - progresstoCenter) * 100);
        }

    }

Then go back to your onLayoutInflated() method, and type the following:

    CustomScrollingLayoutCallback customScrollingLayoutCallback = new CustomScrollingLayoutCallback();
    your_recycler_view.setLayoutManager(new WearableLinearLayoutManager(your_context, customScrollingLayoutCallback));
    your_recycler_view.setCircularScrollingGestureEnabled(true);

done.

Michael
  • 31
  • 3
  • In my case,middle Icon Size is not Increasing the size If i Scroll up and down.How can i resolve this issue? – kavie Mar 15 '18 at 06:29
1

This is now possible with Android Wear 2.0's WearableRecyclerView.

According to Android Developer Docs:

Wear 2.0 introduces the WearableRecyclerView class for displaying and manipulating a vertical list of items optimized for round displays. WearableRecyclerView extends the existing RecyclerView class to provide a curved layout and a circular scrolling gesture in wearable apps.

You may like to read more about Android Wear 2.0 Preview 3.

Sufian
  • 6,405
  • 16
  • 66
  • 120
  • 1
    People who're downvoting this answer, please post your reasoning at least. This isn't a "link-only" answer. It quotes relevant text from the link. And if you've got a better answer then please don't hide behind a down vote, instead post it as an answer. – Sufian Aug 27 '17 at 15:59
  • The circular scrollbar is showing up as straight :( – D Lad Apr 04 '22 at 18:43