android基本图库库代码错误?

时间:2014-05-04 20:24:32

标签: android

我正在开发主要活动,此时垂直显示多个图像,可以向下滚动。之后我会将每个图像用作视频的缩略图。

但imageview仅显示一张图片 有人可以引导我完成它。

        Resources res = getResources(); //if you are in an activity
        AssetManager am = res.getAssets();
        //String temp="";
        String fileList[];
        try {
            fileList = am.list("thumbs");
            if (fileList != null)
            {   
                for ( int i = 0;i<fileList.length;i++)
                {
                    Log.d("",fileList[i]); 
                    //temp = temp + fileList[i] + ", ";
                    if (i == 0)
                    {
                        mImage = (ImageView)findViewById(R.id.imageView1);
                        Drawable d = fetchThumb(fileList[0]);
                        mImage.setImageDrawable(d);
                    }
                    else if(i == 1)
                    {
                        mImage = (ImageView)findViewById(R.id.imageView2);
                        Drawable d = fetchThumb(fileList[1]);
                        mImage.setImageDrawable(d);
                    }
                    else if(i == 2)
                    {
                        mImage = (ImageView)findViewById(R.id.imageView3);
                        Drawable d = fetchThumb(fileList[2]);
                        mImage.setImageDrawable(d);
                    }
                }
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }   
    }


    public Drawable fetchThumb(String filename)
    {
            try 
            {
            InputStream ims = getAssets().open(filename);
            Drawable d = Drawable.createFromStream(ims, null);
                return d;
        }
        catch(IOException ex) 
        {return null;}

    }

xml file to display images:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:isScrollContainer="true"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:orientation="vertical" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <ImageView
            android:id="@+id/imageView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>


    </LinearLayout>

</RelativeLayout>

0 个答案:

没有答案