如何在滚动时修改RecyclerView行的大小?

任何人都可以告诉我如何将行元素大小与行位置同步:在屏幕中心上方或下方变小以适合安卓佩戴手表上的圆形屏幕?

如果您正在使用可穿戴设备,则可以使用WearableListView

如果是这样,在你的适配器,你有你的物品类代表你的行。 这个类可以实现WearableListView.OnCenterProximityListener 。 在那里,你可以在回调中激活你的视图:一个没有动画的小例子:

 private static class Item extends LinearLayout implements WearableListView.OnCenterProximityListener { private FontTextView label; public Item(Context context) { super(context); View.inflate(context, R.layout.match_center_item, this); label = (FontTextView) findViewById(R.id.label); } @Override public void onCenterPosition(boolean animate) { label.setAlpha(EXPAND_LABEL_ALPHA); } @Override public void onNonCenterPosition(boolean animate) { label.setAlpha(SHRINK_LABEL_ALPHA); } } 

您可以将RecyclerView.OnScrollListener添加到您的RecyclerView中,并且在Scrolled中您可以遍历所有的孩子,并找到他们在屏幕上的位置(kotlin code):

 for(i in 0..this.childCount){ val view = this.getChildAt(i) when(i){ in 0..this.childCount/2 -1-> {view.scaleX = i.toFloat()/(this.childCount/2) view.scaleY== i.toFloat()/(this.childCount/2) } this.childCount/2 -> {view.scaleX = 1F ; view.scaleY = 1F} else ->{view.scaleX = (this.childCount-i).toFloat()/(this.childCount/2) view.scaleY== (this.childCount-i).toFloat()/(this.childCount/2) } } }