1

これは私のレイアウト ギャラリーです //gallery.xml

    <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>

私の質問は、グリッドビューのすべての画像ギャラリーにどのように表示できますか? アプリのギャラリー (SD カード) から画像を選択する方法について知っていますか? ただし、アプリにとどまってアルバムの名前も取得する必要があります。

4

1 に答える 1

-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 と data をクエリとして渡したことに注意してください。これらのフィールドを取得するには、次のようにします。

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

}

次に、場所に基づいて画像を表示したり、日付順に並べ替えたりできます...

于 2013-10-23T13:02:16.947 に答える