我遇到的问题是我动态生成ImageViews并在Linearlayout中添加它们。但问题是第一次它很好地工作意味着在LinearLayout中添加了所有图像视图,但是当我们第二次运行相同的代码时它只添加一个图像。我不知道为什么?请建议我解决方案。
代码:
protected void callAfterEff() {
layout_Pagination.removeAllViews();
img_Pagination = new ImageView[Overview_Years.size()];
paramsPagination = new LinearLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
//params.weight = 0.5f;
paramsPagination.gravity= Gravity.CENTER_VERTICAL;
paramsPagination.setMargins(10, 2, 0, 0);
// TODO Auto-generated method stub
for(int i=0;i<overviewYears.getYears().size();i++)
{
img_Pagination[i] = new ImageView(Overview.this);
img_Pagination[i].setLayoutParams(paramsPagination);
/*if(count==i)
{
img_Pagination[count].setBackgroundResource(R.drawable.pagination_selected);
}
else
{*/
img_Pagination[i].setBackgroundResource(R.drawable.pagination_unselected);
//}
layout_Pagination.addView(img_Pagination[i]);
}
}