2015-05-09 54 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);

相关问题