I'm making mini bookmarks application. The idea is to populate the relative layout with favicons of sites that are stored in browser's bookmark database. I extracted blob images from the database and converted them to drawables using Drawable.createFromStream method. How can I properly sizeup those imageviews because currently they are very small? Another problem that I have is the relative layout. How can I properly populate the horizontal area with icons so when it reaches end of screen they go in new line?
Here's my code:
@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.setContentVi开发者_运维技巧ew(scrollView);
}
}
There are a number of ways you can approach what you're trying to do.
But ImageViews have a scale type, so the image can be forced to scale up but maintain ratio or scale up so the entire view is filled
http://developer.android.com/reference/android/widget/ImageView.ScaleType.html
In terms of filling the screen, you'll need to determine either the number of icons per row OR dynamically decide the number of them and size them.
精彩评论