如何在上一个下面创建动态图像视图添加?

时间:2015-05-09 15:40:06

标签: java imageview dynamically-generated

这是我的.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);}

`

但不起作用。你能救我吗?

1 个答案:

答案 0 :(得分:0)

请在图片视图下方放置哪个视图元素:

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

然后拨打mImageView.setLayoutParams(rlp);