2011-02-11 68 views
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); 
} 

}

回答

1

有很多,你可以接近你想要做什麼樣的方式。

但是ImageViews產生水垢類型,因此圖像可以被強制擴展,但保持比或擴大,從而整個視圖中填充

http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

在填充屏幕方面,你」您需要確定每行圖標的數量或者動態確定它們的數量並調整它們的大小。

相關問題