android框架布局,带有水平滚动条和重叠图像
我想创建一个框架布局来放置来自数据库的大量图像,这些图像需要是一个水平滚动列表。图像视图是基于数据库值动态创建的。图像必须像附件一样重叠。这是我的xmlandroid框架布局,带有水平滚动条和重叠图像,android,android-layout,android-view,android-gui,Android,Android Layout,Android View,Android Gui,我想创建一个框架布局来放置来自数据库的大量图像,这些图像需要是一个水平滚动列表。图像视图是基于数据库值动态创建的。图像必须像附件一样重叠。这是我的xml <HorizontalScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true
<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>
如果这些卡中的每一张都是ImageView,那么您就不能使用任何标准的ViewGroups(如FrameLayout)来实现这一点,因为FrameLayout会将一个视图堆叠在其他视图之上。您必须创建自己的ViewGroup子类,并根据需要放置ImageView。请注意,这不是一件容易的事情。@Luksprog是否有其他方法来实现它,而不是ImageView和view group?。我可以使用自定义视图绘制位图吗。但问题是,我必须用新的位图替换单击的位图。您可以尝试创建自定义视图并自己绘制图像,但是,如果您计划稍后替换它们,这将不是一项容易的任务。谢谢您的评论。我已经使用相对布局完成了,并将边距设置为边距+=图像宽度/2。
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();
}