,我在一個Android應用程序 其中 相對佈局在相對佈局動態顯示多ImageViews的Android
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="2dp"
android:adjustViewBounds="true"
android:background="@drawable/background" />
<RelativeLayout
android:id="@+id/mymainlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
>
</RelativeLayout>
我的問題是我不能以編程方式繪製所有ImageViews在其顯示的相對佈局工作只有一個圖像。 這裏是我的代碼
for (int i = 0; i < realAnswer; i++) {
arrayofImages[i] = new ImageView(this);
arrayofImages[i].setImageResource(imageId[imageNumber]);
arrayofImages[i].setId(i);
if(i!=0)
{
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.LEFT_OF, arrayofImages[i-1].getId());
//arrayofImages[i].setLayoutParams(params);
nn.addView(arrayofImages[i],params);
}
else
{
nn.addView(arrayofImages[i]);
}
}
這裏nn是我的主要佈局
任何幫助,請???
你應該動態地添加圖片觀點,參見[此處輸入鏈接的描述] [1] [1]:http://stackoverflow.com/questions/16942486/add-imageview-dynamic-to-existing-view –
你想要達到什麼目的? –
我想在佈局中顯示10個圖像。我已經使用線性佈局,但它最多隻顯示7幅圖像。重量總和爲10. –