Android中多图片选择器PhotoPicker库的使用(仿微信,秒杀MultiImageSelector)自己修改的多选

Android中多图片选择器PhotoPicker库的使用(仿微信,秒杀MultiImageSelector)自己修改的多选_第1张图片

核心代码:

public class MainActivity extends AppCompatActivity {
//  展示路径的TextView
    private TextView mResultText;
//  调用相册的按钮
    private Button button;
//  选择图片的路径
    private ArrayList mSelectPath;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        button = (Button) findViewById(R.id.button);
        mResultText = (TextView) findViewById(R.id.result);


        if (button != null) {
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    pickImage();
                }
            });
        }
    }
    private void pickImage() {
//      调用相册中的相片,用Picasso展示
        PhotoPicker.init(new PicassoImageLoader(), null);
//      启用相机
        boolean showCamera = true;
//      最大选择5张
        int maxNum = 5;
//      显示3列
        int columns = 3;
        Load load = PhotoPicker.load()
                .showCamera(showCamera)
                .filter(PhotoFilter.build().showGif(false).minSize(2 * 1024))
                .gridColumns(columns);
//      传入最大选择的数量,和路径
        PhotoSelectBuilder builder = load.multi().maxPickSize(maxNum).selectedPaths(mSelectPath);
        builder.start(MainActivity.this);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == PhotoPicker.REQUEST_SELECTED) {
            if (resultCode == RESULT_OK) {
                mSelectPath = data.getStringArrayListExtra(PhotoPicker.EXTRA_RESULT);
                StringBuilder sb = new StringBuilder();
                for (String p : mSelectPath) {
                    sb.append(p);
                    sb.append("\n");
                }
                mResultText.setText(sb.toString());
            }
        }
    }




}
源码下载:

http://download.csdn.net/detail/zhaihaohao1/9608825

参考:

https://github.com/muhezi/PhotoPicker

你可能感兴趣的:(相机)