android gridview获取所有图像
这是我的布局图库 //gallery.xmlandroid gridview获取所有图像,android,gridview,Android,Gridview,这是我的布局图库 //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"> <Fra
<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所有图像库中显示?
我知道,但我需要留在我的应用程序中,并获取相册的名称。是否只在手机上显示所有图像?还是要像gallery应用程序一样显示它,并首先显示文件夹 编辑:以下是获取设备上所有图像(内部和外部)的代码 注意您需要获得读取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);
请注意,我传入了日期和数据作为查询,因此要获取这些字段,您可以这样做
while(cursor.moveToNext()){
long date =cursor.getLong(0);
String fileLoc=cursor.getString(1);
}
然后,您可以根据图像的位置显示图像,按日期排序等等。我不喜欢显示gallery应用程序,因为我会丢失按钮。谢谢,我在以下方面找到了一个很好的解决方案: