【问题标题】:how to make own custom camera gallery view如何制作自己的自定义相机图库视图
【发布时间】:2016-02-27 05:59:46
【问题描述】:

我正在开发 android 相机应用程序,当我单击它时将图像保存在画廊中,当我单击画廊视图时,它会显示手机的默认画廊,但我想要自己的自定义视图,其中包含删除、分享、收藏等按钮。我该如何实现这个请帮助我

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);
            }
        }
    }
}

【问题讨论】:

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


    【解决方案1】:

    以这个例子为基础。

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

    programlist.xml 添加您的按钮。

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

    MainActivity 中将descendantfocusability 设置为Gridview

    【讨论】:

    • 感谢您的回复,但实际上我想要 imageview 而不是画廊视图,因为当我点击保存的点击图像时,它会显示在预览中,我们可以向左或向右滑动
    猜你喜欢
    • 1970-01-01
    • 2020-03-09
    • 2020-01-05
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    • 2011-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多