This is how I solved it. This may not be the best way, but it works. If anyone has a better solution, edit this post or create a new post.
First I have a drawable that creates a round object.
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="#eeffffff" /> <corners android:bottomRightRadius="200dip" android:bottomLeftRadius="200dip" android:topRightRadius="200dip" android:topLeftRadius="200dip"/> </shape>
Then in my layout I created the following structure in my case, I needed to have points vertically. But you can also create a horizontal version.
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="horizontal"> <RelativeLayout android:layout_alignParentRight="true" android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="vertical"> <LinearLayout android:layout_width="15dp" android:layout_height="wrap_content" android:layout_centerVertical="true" android:id="@+id/dotlayout" android:orientation="vertical"> </LinearLayout> </RelativeLayout> <android.support.wearable.view.GridViewPager android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/pager"> </android.support.wearable.view.GridViewPager> </RelativeLayout>
I tried to make the dots as close as possible to the version of Google. And I got it pretty close, but not perfect, since the distance between the points is a pixel or two. I used buttons at the moment, but it could be any representation you could make, perhaps images would be better:
I added points to my dotlayout
for(int i = 0; i < numberOfDots; i++){ Button b = new Button(this); configDot(b, 4, 2); dotLayout.addView(b); }
Remember to make the start button large:
configDot((Button) dotLayout.getChildAt(0), 6, 1);
And the Config method:
private void configDot(Button b, int size, int margin){ b.setBackground(getResources().getDrawable(R.drawable.roundbutton)); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(getPxFromDp(size), getPxFromDp(size)); p.gravity = Gravity.CENTER_HORIZONTAL; p.setMargins(0, margin, 0, margin); b.setLayoutParams(p); } private int getPxFromDp(int dp){ return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); }
On my pager, I added onPageChangeListener , where I reconfigured all the views to have the correct size.
pager.setOnPageChangeListener(new GridViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int i, int i2, float v, float v2, int i3, int i4) {} @Override public void onPageSelected(int i, int i2) { for(int j = 0; j < dotLayout.getChildCount(); j++){ configDot((Button) dotLayout.getChildAt(j), 4, 2); } if(dotLayout.getChildCount() > i) { configDot((Button) dotLayout.getChildAt(i), 6, 1); } } @Override public void onPageScrollStateChanged(int i) {} });
It looks like this:
