My WearableRecycler查看线条像三角形一样,并不像手表的主屏幕那样弯曲。我在代码中找不到任何错误。
ShareActivity:
private void initListView() {
WearableRecyclerView recyclerView = findViewById(R.id.lVDevices);
recyclerView.setEdgeItemsCenteringEnabled(true);
final ScrollingLayoutCallback scrollingLayoutCallback =
new ScrollingLayoutCallback();
adapter = new ShareAdapter(new ShareAdapter.Callback() {
@Override
public void onDeviceClicked(int position, String deviceName) {
onListItemClick(position, deviceName);
}
});
recyclerView.setLayoutManager(
new WearableLinearLayoutManager(this, scrollingLayoutCallback));
recyclerView.setAdapter(adapter);
}
ScrollingLayoutCallback:
public class ScrollingLayoutCallback extends WearableLinearLayoutManager.LayoutCallback {
private static final float MAX_ICON_PROGRESS = 0.65f;
@Override
public void onLayoutFinished(View child, RecyclerView parent) {
// Figure out % progress from top to bottom
float centerOffset = ((float) child.getHeight() / 2.0f) / (float) parent.getHeight();
float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;
// Normalize for center
float mProgressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
// Adjust to the maximum scale
mProgressToCenter = Math.min(mProgressToCenter, MAX_ICON_PROGRESS);
child.setScaleX(1 - mProgressToCenter);
child.setScaleY(1 - mProgressToCenter);
}
}
的ListView-XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/refreshlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<android.support.wear.widget.WearableRecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lVDevices"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
android:scrollbars="vertical"/>
</android.support.v4.widget.SwipeRefreshLayout>
</RelativeLayout>
行的XML
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/lVDevices_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:drawableStart="@drawable/point_img"
android:layout_centerHorizontal="true"
android:textSize="18sp">
</TextView>
Callback方法中存在问题吗?我的意思是计算中存在错误,因为它来自开发者网站。
编辑1:ScrollingCallback类中的新数学
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);
child.setScaleX(progresstoCenter);
child.setScaleY(progresstoCenter);