android框架布局与水平滚动条和重叠图像

时间:2012-05-08 10:19:04

标签: android android-layout android-view android-gui

我想创建一个Frame布局来放置来自数据库的大量图像,这些图像需要是一个水平可滚动列表。图像视图基于数据库值动态创建。图像必须像附件一样重叠。这是我的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();

 }

Screen 1 SCreen 2

0 个答案:

没有答案