扩展RelativeLayout
这是我在创建具有可自定义过度滚动的 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);
奇怪的是,这给出了这个(我已将相对布局设置为黑色以显示边缘和发光):
如您所见,顶部边缘漂浮在不知名的地方,底部的光芒已经缩小到很小的尺寸......到底是什么?
This is more work I'm doing on creating a ListView with customisable overscroll.
I want to create a Custom element which extends RelativeLayout but adding child view's isn't working at all well. The code seems right but the view looks slightly insane.
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);
This, strangely, gives this (I've set the relative layout to black to show the edges and glows):
As you can see, the top edge is floating in the middle of nowhere and the bottom glow has shrunk to a teeny tiny size.... What the heck?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
喜欢写下问题如何帮助我解决它:
对两个组件使用相同的 LayoutParams 会让事情变得很奇怪。看起来很繁重,但它确实可以解决问题。
Love how writing down the problem helps me solve it:
Using the same LayoutParams for two components make's things go weird. Seems onerous but it does fix things.