android - 我怎样才能显示一个中间有加号的空 ImageView

标签 android

我看到许多用户可以上传个人资料图片的应用程序,其中有一个带有加号的空框。用户点击的地方,然后加载图库等。

在图像内部加载缩略图等方面,它的外观和行为似乎非常普遍,所以我想知道是否有这些应用程序使用的小部件或自定义 View 。如果没有,那么有人可以给我一个关于如何从头开始实现的想法。

最佳答案

使用包含以下内容的 onClick 方法使空 ImageView 可点击:

Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, "Select Picture"), 100 );

然后在

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    uiHelper.onActivityResult(requestCode, resultCode, data);
    if(requestCode == 100 && data != null && data.getData() != null) {
        Uri _uri = data.getData();

        //User picked an image.
        Cursor cursor = getActivity()
                .getContentResolver()
                .query(_uri, new String[] { android.provider.MediaStore.Images.ImageColumns.DATA }, null, null, null);

        cursor.moveToFirst();

        //Link to the image
        final String imageFilePath = cursor.getString(0);
        myAvatar = BitmapFactory.decodeFile(imageFilePath);
        ImageView iv = (ImageView) yourView.findViewById(R.id.yourview);
        iv.setImageBitmap(myAvatar);
        cursor.close();
    }
    super.onActivityResult(requestCode, resultCode, data);
}

关于android - 我怎样才能显示一个中间有加号的空 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18513707/

相关文章:

android - 使用apply插件时出现错误: 'com.android.library'

java - double 、逗号和点

android - Android 上的 Phonegap 地理定位

android - 在 Android 上移动到 SD 卡

android - 使用 Mosby 实现非 ViewGroup MVP Android View

java - Android SAX 实现不能抛出异常

android - 如何控制 ListView 重新加载。

android - WebView.getUrl() 返回 null

具有 multidex 的 Android 应用程序(Xamarin Forms) - 启动如此缓慢

android - Android无法发送HTTP请求