这是我在创建具有可自定义过度滚动的 ListView 方面所做的更多工作。
我想创建一个扩展 RelativeLayout 但添加子视图的自定义元素根本无法正常工作。代码看起来正确,但视图看起来有点疯狂。
underscrollEdge = new ImageView(context);
underscrollEdge.setImageResource(R.drawable.underscroll_edge);
underscrollGlow = new ImageView(context);
underscrollGlow.setImageResource(R.drawable.underscroll_glow);
overscrollGlow = new ImageView(context);
overscrollGlow.setImageResource(R.drawable.overscroll_glow);
overscrollEdge = new ImageView(context);
overscrollEdge.setImageResource(R.drawable.overscroll_edge);
RelativeLayout.LayoutParams topLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
topLayout.addRule(RelativeLayout.ALIGN_PARENT_TOP);
addView(underscrollEdge, topLayout);
addView(underscrollGlow, topLayout);
RelativeLayout.LayoutParams bottomLayout = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
bottomLayout.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
addView(overscrollGlow, bottomLayout);
addView(overscrollEdge, bottomLayout);
奇怪的是,这给出了这个(我已将相对布局设置为黑色以显示边缘和发光):
如您所见,顶部边缘漂浮在不知名的地方,底部发光已缩小到很小的尺寸......到底是什么?