【发布时间】:2012-07-20 14:45:48
【问题描述】:
我正在尝试在运行时将一系列图像添加到当前RelativeLayout 下另一个TextView。到目前为止,我让它显示部分正确,但不完全正确。我不能让他们搬到另一排。我希望有人能帮我一把,告诉我正确的方法。系列图片会出现在这个TextView(R.id.date)下面:
TextView date = (TextView) findViewById(R.id.date);
//// image view start //////
int photos = Integer.parseInt(total_photo);
RelativeLayout mainLayout = (RelativeLayout) findViewById(R.id.relative_layout_b);
for (int i = 0; i < limit; i++){
final ImageView imageView = new ImageView (this);
imageView.setId(i);
imageView.setImageResource(R.drawable.photo_frame);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
imageView.setPadding(10, 10, 0, 0);
imageView.setAdjustViewBounds(true);
imageView.setMaxHeight(80);
imageView.setMaxWidth(80);
lp.addRule(RelativeLayout.BELOW, R.id.date);
lp.addRule(RelativeLayout.RIGHT_OF, imageView.getId() - 1);
imageView.setLayoutParams(lp);
mainLayout.addView(imageView);
}
目前只显示总照片数量 - 1(即:有5张时,只显示4张);我想让每一行显示 5,如果达到 6、11、16 等,我会立即移动到下一行。这个布局嵌套在ScrollView 和RelativeLayout 中,因为我有很多视图。所以,为此我将不得不坚持使用RelativeLayout。
【问题讨论】:
-
我建议将 GridView 作为您的父布局,并将您的 RelativeLayout 设置为视图以膨胀到您的 GridView。
标签: android android-layout android-relativelayout android-imageview