0
我正在製作迷你書籤應用程序。這個想法是用存儲在瀏覽器書籤數據庫中的網站的圖標填充相對佈局。我從數據庫中提取blob圖像,並使用Drawable.createFromStream方法將它們轉換爲drawable。我怎樣才能正確地確定這些圖像的大小,因爲目前它們很小?我的另一個問題是相對佈局。我怎樣才能正確使用圖標填充水平區域,所以當它到達屏幕的末尾時,他們會換行?如何在所有屏幕上正確調整imageview的大小?
這裏是我的代碼:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ScrollView scrollView = new ScrollView(this);
RelativeLayout relativeLayout = new RelativeLayout(this);
ImageView bookmark;
scrollView.addView(relativeLayout);
this.startManagingCursor(cursor);
Uri Bookmarks = Browser.BOOKMARKS_URI;
cursor = managedQuery(
Bookmarks, projection, selection, null, Browser.BookmarkColumns.VISITS + " DESC");
if (cursor.moveToFirst()) {
int idCounter = 1;
ByteArrayInputStream blobImage;
do{
bookmark = new ImageView(this);
bookmark.setId(idCounter++);
blobImage = new ByteArrayInputStream(
cursor.getBlob(cursor.getColumnIndex(BookmarkColumns.FAVICON)));
bookmark.setImageDrawable(
Drawable.createFromStream(blobImage, "" + bookmark.getId()));
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
if(idCounter > 1) {
params.addRule(RelativeLayout.BELOW, bookmark.getId() - 1);
}
relativeLayout.addView(bookmark, params);
} while (cursor.moveToNext());
}
this.setContentView(scrollView);
}
}