如何在Android Wear中为2D Pickers添加页面点?

use*_*613 5 android wear-os

一些股票应用程序使用这种"页面点"来指导用户.当我实现2D选择器时,我发现页面点不是它的一部分.我尝试使用图像来模拟效果,但是ImageView当用户从一个页面到另一个页面滑动时,我会移动页面.

如何实现这种在用户滑动时不移动的"页面点"?此外,我可以控制这些点是否/何时出现和褪色?

在此输入图像描述

小智 17

您现在可以(从v1.1开始)使用DotsPageIndicator类,如下所示:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <android.support.wearable.view.GridViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:keepScreenOn="true" />

    <android.support.wearable.view.DotsPageIndicator
        android:id="@+id/indicator"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal|bottom"/>
</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

然后在您的Activity类中:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_gridview);

    final GridViewPager pager = (GridViewPager) findViewById(R.id.pager);
    DotsPageIndicator dots = (DotsPageIndicator) findViewById(R.id.indicator);
    dots.setPager(pager);
}
Run Code Online (Sandbox Code Playgroud)