如何制作自己的自定义相机库视图

时间:2016-02-27 05:59:47

标签: android android-intent android-camera android-gallery

我正在研究安卓摄像头应用程序,当我点击它保存库中的图像当我点击图库视图它显示默认的移动画廊但我想要自己的自定义视图按钮,如删除,分享,收藏。我该如何实现这一点请帮助我

public void clickedGallery(View view) {
    if (MyDebug.LOG)
        Log.d(TAG, "clickedGallery");
    //Intent intent = new Intent(Intent.ACTION_VIEW, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
    Uri uri = null;
    Media media = getLatestMedia();
    if (media != null) {
        uri = media.uri;
    }

    if (uri != null) {
        // check uri exists
        if (MyDebug.LOG)
            Log.d(TAG, "found most recent uri: " + uri);
        try {
            ContentResolver cr = getContentResolver();
            ParcelFileDescriptor pfd = cr.openFileDescriptor(uri, "r");
            if (pfd == null) {
                if (MyDebug.LOG)
                    Log.d(TAG, "uri no longer exists (1): " + uri);
                uri = null;
            }
            pfd.close();
        } catch (IOException e) {
            if (MyDebug.LOG)
                Log.d(TAG, "uri no longer exists (2): " + uri);
            uri = null;
        }
    }
    if (uri == null) {
        uri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    }
    if (!is_test) {
        // don't do if testing, as unclear how to exit activity to finish test (for testGallery())
        if (MyDebug.LOG)
            Log.d(TAG, "launch uri:" + uri);
        final String REVIEW_ACTION = "com.android.camera.action.REVIEW";
        try {
            // REVIEW_ACTION means we can view video files without autoplaying
            Intent intent = new Intent(REVIEW_ACTION, uri);
            this.startActivity(intent);
        } catch (ActivityNotFoundException e) {
            if (MyDebug.LOG)
                Log.d(TAG, "REVIEW_ACTION intent didn't work, try ACTION_VIEW");
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            // from http://stackoverflow.com/questions/11073832/no-activity-found-to-handle-intent - needed to fix crash if no gallery app installed
            //Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("blah")); // test
            if (intent.resolveActivity(getPackageManager()) != null) {
                this.startActivity(intent);
            } else {
                preview.showToast(null, R.string.no_gallery_app);
            }
        }
    }
}

1 个答案:

答案 0 :(得分:0)

使用此示例作为基础。

https://www.caveofprogramming.com/guest-posts/custom-gridview-with-imageview-and-textview-in-android.html

programlist.xml添加按钮。

CustomAdapter.java方法的getView中,实现按钮监听器。

MainActivity设置descendantfocusability到Gridview