1

我想创建一个框架布局来放置数据库中的一些图像,这些图像需要是一个水平滚动列表。图像视图是根据数据库值动态创建的。图片必须像附件一样重叠。这是我的xml

 <HorizontalScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true" 
                android:layout_marginTop="20dp"
                >

            <FrameLayout
                android:id="@+id/frmLayout"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:scrollbars="horizontal"
                android:layout_weight="1"
                 >

            </FrameLayout>

        </HorizontalScrollView>

这是java

public void getAllImages(){

        cursorImages = dbAdapter.fetchImages();
        if (cursorImages.moveToFirst()) {
           BitmapFactory.Options options=new BitmapFactory.Options();
        options.inSampleSize = 2;
        do {
            String filename = cursorImages.getString(cursorImages
                    .getColumnIndex("filename"));
            try {
                InputStream ims = getAssets().open("images/" + filename);
                Bitmap bm = BitmapFactory.decodeStream(ims,null,options);
                Matrix mat = new Matrix();
                mat.postRotate(30);
                Bitmap bMapRotate = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), mat, true);
                 ImageView im = new ImageView (this);
                 im.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));  
                 im.setImageBitmap(bMapRotate);
                 frmLayout.addView(im,new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));       
            } catch (IOException ex) {

            }
        } while (cursorImages.moveToNext());

    }
    cursorImages.close();

 }

屏幕一 屏幕 2

4

0 回答 0