2015-05-09 82 views
0

這是我的.xlm文件。對不起,但我是新的Java和Android。我要添加新的ImageView的,動態的,在佈局,每個人都將是上一個下面:如何在前一個下面創建動態圖像查看?

`

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     > 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:id="@+id/frame1"> 
     </LinearLayout> 
    </ScrollView> 
</LinearLayout> 
` 

,這是我的循環:

` 

for (int i = 0;i < num_max; i++){ 
       name = String.valueOf(i) + ".jpg"; 
       RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT); 
       rlp.addRule(RelativeLayout.BELOW); 
       rlp.addRule(RelativeLayout.ALIGN_START); 
       rlp.addRule(RelativeLayout.ALIGN_LEFT); 
       LinearLayout frameLayout = (LinearLayout) findViewById(R.id.frame1); 
       mImageView = new ImageView (this); 
       Bitmap bitmap = BitmapFactory.decodeFile(url_image+name); 
       mImageView.setImageBitmap(bitmap); 
       frameLayout.addView(mImageView,rlp);} 

`

但不起作用。你可以幫我嗎?

+0

請形容,究竟是行不通的。你有任何錯誤,如果是的話請添加堆棧跟蹤。 –

+0

沒有。沒有錯誤。我想動態添加imageview,在垂直滾動視圖的前一個下方,但使用此代碼,我無法做到這一點,我沒有其他想法來做到這一點 – Giuseppe

回答

0

Spezifiy低於此視圖元素的圖像視圖應該放在有:

rlp.addRule(RelativeLayout.BELOW,R.id.theviewwhichisabove); 

,然後調用mImageView.setLayoutParams(rlp);

相關問題