【发布时间】:2016-07-19 08:49:45
【问题描述】:
【问题讨论】:
-
这将无济于事。 BoxInsetLayout 设置了一个方形插图,但这里的项目与边缘对齐(即使滚动条也是圆形的)
标签: android listview android-wear-2.0
【问题讨论】:
标签: android listview android-wear-2.0
首先,您需要将 ListView 替换为 WearableRecyclerView。
它可以像普通的 ListView 一样使用。但请确保您从android.support.wear.widget导入正确的。 不要使用来自android.support.wearable.view 的那个。这个应该被划掉,所以你不会花很长时间来检查你是否使用了正确的。如果只有一个 WearableRecyclerView 可供选择,请确保将 compile 'com.android.support:wear:27.0.0' 添加到 build.gradle (wear) 文件中的依赖项中。
还要确保您在 activity.xml 中使用了<android.support.wear.widget.WearableRecyclerView/>。如果您只想要一个没有任何自定义项目缩放的圆形 ListView,只需在您的 onLayoutInflated() 方法中调用它:
your_recyclerview.setEdgeItemsCenteringEnabled(true);
your_recyclerview.setLayoutManager(new WearableLinearLayoutManager(your_activity_context));
如果您想让项目在靠近屏幕中心时按比例放大,事情会变得有点复杂。
首先:将其粘贴到您的 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);
}
}
然后返回到您的 onLayoutInflated() 方法,并输入以下内容:
CustomScrollingLayoutCallback customScrollingLayoutCallback = new CustomScrollingLayoutCallback();
your_recycler_view.setLayoutManager(new WearableLinearLayoutManager(your_context, customScrollingLayoutCallback));
your_recycler_view.setCircularScrollingGestureEnabled(true);
完成。
【讨论】:
现在可以使用 Android Wear 2.0 的WearableRecyclerView。
Wear 2.0 引入了
WearableRecyclerView类,用于显示和 操作为圆形显示优化的垂直项目列表。WearableRecyclerView将现有的RecyclerView类扩展为 在可穿戴设备中提供弯曲布局和圆形滚动手势 应用程序。
您可能想了解更多关于Android Wear 2.0 Preview 3的信息。
【讨论】: