0

我正在将一系列图像(以编程方式)从 URL 加载到 RelativeLayout,问题是它们都出现在同一个位置重叠,我如何才能将图像加载到彼此下方?

这是代码的一部分:

RelativeLayout imageWrapper = (RelativeLayout) findViewById(R.id.image_wraper);

    try {
        for(int i=0; i<articuloClick.LlenarImagenes(posicion).getImagenesSrc().size(); i++){
            ImageView imagen=new ImageView(this);
            LinearLayout.LayoutParams vp = 
                    new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                                    LayoutParams.WRAP_CONTENT);
            imagen.setLayoutParams(vp);        
            imagen.setImageBitmap(run(articuloClick.LlenarImagenes(posicion).getImagenesSrc().get(i)));
            imageWrapper.addView(imagen);

        }
    } catch (IOException  e) {
        Log.e("Escepcion IO:", e.toString());
    } catch (XmlPullParserException e) {
        Log.e("Escepcion XMLPullParser:", e.toString());
    }

这是 xml(编辑为更具可读性):

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
  android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:paddingTop="20dp"   android:paddingLeft="20dp"      android:paddingRight="20dp" android:paddingBottom="20dp"
android:background="#eeeeee"
android:id="@+id/art">     
<ScrollView
    android:layout_width="wrap_content" android:layout_height="wrap_content">       
    <LinearLayout 
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="10dp"   android:paddingLeft="10dp"  android:paddingRight="10dp" android:paddingBottom="10dp"
        android:background="@drawable/borde">

      (...)

      <RelativeLayout 
            android:id="@+id/image_wraper"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </LinearLayout>
  </ScrollView>
</LinearLayout> 

这就是我得到的:

来自设备的带有 2 个重叠图像的图像

非常感谢。

4

1 回答 1

1

最简单的方法是将您的更改RelativeLayoutLinearLayoutwithorientation="vertical"

<LinearLayout 
    android:id="@+id/image_wraper"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

然后在代码中:

LinearLayout imageWrapper = (LinearLayout ) findViewById(R.id.image_wraper);

您的图像将出现在另一张下方。

于 2013-06-19T14:13:27.590 回答