2013-06-19 117 views
0

我正在從一個URL加載一系列圖片(programaticaly)到一個RelativeLayout,問題是它們看起來都在同一個地方重疊,我怎麼可以將圖像加載到另一個之下?ImageViews裏面的相對佈局重疊

下面是部分代碼:

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

最簡單的方法是改變你與RelativeLayoutLinearLayoutorientation="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); 

你的圖像就會出現一個在另一個之下。

+0

謝謝!令人驚訝的工作! – Trifit

+0

@Trifit如果解決了您的問題,請考慮將答案標記爲已接受。這就是爲什麼(http://meta.stackexchange.com/a/5235)謝謝! –