ImageViews内部相对布局重叠

时间:2013-06-19 14:10:06

标签: android imageview

我正在从URL将一系列图像(programaticaly)加载到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> 

这就是我得到的:

Image from the device with 2 overlapped images

非常感谢。

1 个答案:

答案 0 :(得分:1)

最简单的方法是使用RelativeLayout

LinearLayout更改为orientation="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);

您的图片会一个接一个地出现。