【发布时间】:2011-08-17 00:41:22
【问题描述】:
我正在使用Gallery 来显示事件的水平时间线。一些事件得到Gravity.TOP 和一些Gravity.BOTTOM 将它们对齐在显示年份的漂亮线条之上或之下。到目前为止,一切顺利。
我想改变顶部元素的左边距属性,所以没有巨大的间隙并且元素看起来交错。例如:为每个在顶部对齐的元素设置负左边距。
Gallery 的每个元素都包含在一个 LinearLayout 上,可以设置一个 MarginLayoutParams 实例以编程方式更改边距。但是,在适配器内部使用MarginLayoutParams 时,我得到了ClassCastException,因为库代码这样做:
// Respect layout params that are already in the view. Otherwise
// make some up...
Gallery.LayoutParams lp = (Gallery.LayoutParams) child.getLayoutParams();
关于如何克服这个问题的任何想法或提示?
【问题讨论】:
-
“我在适配器内部使用 MarginLayoutParams 时遇到 ClassCastException” - 你能告诉我们你的 MarginLayoutParams 是如何与你的适配器交互的吗?
标签: android android-layout android-gallery