与部分重叠的自定义视图中的项目列表视图(安卓) [英] List view with custom view items with partially overlaps (Android)
问题描述
我想实现一个列表在Android中包含一些自定义的视图。 我的问题是我想要的意见将被放在一个接一个,而它们之间几乎没有重叠。就像下面的模式:
I want to implement a list in Android that contains some customized views. My problem is that I want the the views will be put one after the other with a little overlap between them. like in the following schema:
我也希望控制这种重叠以这样的方式,当用户点击的项目之一,他们将移动分开彼此
I also want to control this overlap in such a way that when the user clicks on one of the items, they will move apart from each other.
我试图扩大ListView的,但它似乎很模糊,有什么建议?
I tried to extend ListView but it seems to be very obscured, any suggestions?
编辑: 这样可以更清楚的:
This can be more clear:
我通过设置分隔高度-50dp做到了。 这正是我想要实现,但不知何故,不能在我的应用程序的体现。
I did it by setting the divider height to -50dp. this is exactly what I want to achieve, but somehow it doesn't reflect on my app.
推荐答案
我设法用滚动视图用一个相对布局作为一个孩子来实现这一点。 我再动态地将意见通过定义规则,保证金:
I managed to achieve this by using scroll view with a single relative layout as a child. I then dynamically place the views by defining a rule and margin:
for (int i = 0; i < 30; i++) {
TextView tv = new TextView(context);
tv.setText("Text \n Text" + i);
tv.setBackgroundColor(i % 2 == 0 ? Color.RED : Color.GREEN);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lp.leftMargin = 0;
lp.topMargin = (i * 45);
rl.addView(tv, lp);
}
之后,你可以通过改变他们的Y值控制的子视图的位置(例如:如果你想添加动画)
Later, you can control the positioning of the sub-views by changing their y value (for example: if you want to add animation).
这是最后的结果是:
这篇关于与部分重叠的自定义视图中的项目列表视图(安卓)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!