2013-10-23 13 views
1

這是我的佈局畫廊 //gallery.xml機器人的GridView獲得所有圖像GALLARY

<FrameLayout android:id="@+id/FrameLayout01" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 


     <FrameLayout android:id="@+id/LinearLayout01" 
      android:layout_gravity="top" 
      android:layout_height="50dp" 
      android:layout_width="fill_parent"> 

      <Button android:layout_gravity="left" 
       android:id="@+id/btnPhotos" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="5dp" 
       android:textStyle="bold" 
       android:layout_width="100dp" 
       android:layout_height="40dp" 
       android:text="Photos"/> 

      <TextView android:id="@+id/TextViewAlbumName" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textStyle="bold" 
       android:layout_gravity="center" 
       android:text="Album Name" 
       /> 

      <Button android:layout_gravity="right" 
       android:id="@+id/btnCancel" 
       android:layout_marginRight="5dp" 
       android:layout_marginTop="5dp" 
       android:textStyle="bold" 
       android:layout_width="100dp" 
       android:layout_height="wrap_content" android:text="Cancel"/> 
     </FrameLayout> 

     <GridView xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/gridview" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:columnWidth="90dp" 
      android:numColumns="auto_fit" 
      android:verticalSpacing="10dp" 
      android:horizontalSpacing="10dp" 
      android:stretchMode="columnWidth" 
      android:gravity="center" 
      android:layout_gravity="bottom" 
      android:layout_marginTop="50dp"/> 

    </FrameLayout> 

我的問題是我怎麼能在我的gridview的所有圖片庫顯示? 我知道How to pick an image from gallery (SD Card) for my app?,但我需要留在我的應用程序,並獲得相冊的名稱。

回答

-1

你想只顯示手機上的所有圖像?或者你想像畫廊應用程序那樣顯示它,並首先顯示文件夾?

編輯:這裏是代碼讓你的設備,內部全部圖像和外部 注意您需要權限讀取SD卡,爲了這個工作。

//This gets all external images 
    String[] mProjection = {MediaStore.Images.Media.DATE_TAKEN,MediaStore.Images.Media.DATA}; 
        Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,mProjection,null,null,MediaStore.Images.Media.DATE_ADDED); 

//This gets all internal images 
Cursor cursor = getContentResolver().query(MediaStore.Images.Media.INTERNAL_CONTENT_URI,mProjection,null,null,MediaStore.Images.Media.DATE_ADDED); 

通知我傳入date_taken和數據查詢,因此要獲得這些領域,你會做

while(cursor.moveToNext()){ 
long date =cursor.getLong(0); 
String fileLoc=cursor.getString(1); 

}

然後,您可以顯示圖像基於他們的位置,順序他們按日期等...

+0

我不喜歡顯示畫廊的應用程序,因爲我會失去我的按鈕。 – user2911250

+0

謝謝,我發現了一個很好的解決方案:http://vikaskanani.wordpress.com/2011/07/20/android-custom-image-gallery-with-checkbox-in-grid-to-select-multiple/ – user2911250