拍摄的照片并没有填写imageView:android studio

时间:2018-06-10 22:45:39

标签: android android-studio android-imageview universal-image-loader

当我拍照时,它应该像这样填充图像视图

image takes up imageView

但它看起来像这样(只有当我拍照时才从记忆中选择一张照片)

image does not take up whole imageview

这是我的代码: 通用图片加载程序类

import android.content.Context;
import android.widget.ImageView;

import com.nostra13.universalimageloader.cache.memory.impl.WeakMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;


public class UniversalImageLoader {

    private static final int defaultImage = R.drawable.ic_add_photo;
    private Context mContext;

    public UniversalImageLoader(Context context) {
        mContext = context;
    }

    public ImageLoaderConfiguration getConfig(){
        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .showImageOnLoading(defaultImage)
                .showImageForEmptyUri(defaultImage)
                .showImageOnFail(defaultImage)
                .considerExifParams(true)
                .cacheOnDisk(true).cacheInMemory(true)
                .cacheOnDisk(true).resetViewBeforeLoading(true)
                .imageScaleType(ImageScaleType.EXACTLY)
                .displayer(new FadeInBitmapDisplayer(300)).build();

        ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(mContext)
                .defaultDisplayImageOptions(defaultOptions)
                .memoryCache(new WeakMemoryCache())
                .diskCacheSize(100 * 1024 * 1024).build();

        return configuration;
    }


    public static void setImage(String imgURL, ImageView image){

        ImageLoader imageLoader = ImageLoader.getInstance();
        imageLoader.displayImage(imgURL, image);
    }
}

图像进入代码的片段

public class FragmentUpload extends android.support.v4.app.Fragment implements SelectPhotoDialog.OnPhotoSelectedListener {

    private static final String TAG = "FragmentUpload";


    @Override
    public void getImagePath(Uri imagePath) {
        Log.d(TAG, "getImagePath: setting the image to imageview");
        UniversalImageLoader.setImage(imagePath.toString(), mUploadImage);
        //assign to global variable
        mSelectedBitmap = null;
        mSelectedUri = imagePath;

    }

    @Override
    public void getImageBitmap(Bitmap bitmap) {
        Log.d(TAG, "getImageBitmap: setting the image to imageview");
        mUploadImage.setImageBitmap(bitmap);
        //assign to global variable
        mSelectedUri = null;
        mSelectedBitmap = bitmap;

    }



    public FragmentUpload(){

    }

    private ImageView mUploadImage;
    private EditText mFileName, mDateOfUse, mGrade, mClass, mReflection;
    private Button File;
    private ProgressBar mProgressBar;

    //vars
    private Bitmap mSelectedBitmap;
    private Uri  mSelectedUri;




    //tabs
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.upload_fragment, container, false);

        mUploadImage = view.findViewById(R.id.imageViewAddPhoto);
        mFileName = view.findViewById(R.id.editTextFileName);
        mDateOfUse = view.findViewById(R.id.editTextDate);
        mGrade = view.findViewById(R.id.editTextGrade);
        mClass = view.findViewById(R.id.editTextClass);
        mReflection = view.findViewById(R.id.reflection);
        File = view.findViewById(R.id.file);
        mProgressBar = view.findViewById(R.id.progressBar);

        getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

        init();

        return view;


    }



    private void init(){
        UniversalImageLoader universalImageLoader = new UniversalImageLoader(getActivity());
        ImageLoader.getInstance().init(universalImageLoader.getConfig());
        mUploadImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, "onClick: opening dialog to choose new photo");
                SelectPhotoDialog dialog = new SelectPhotoDialog();
                dialog.show(getFragmentManager(), getString(R.string.dialog_select_photo));
                dialog.setTargetFragment(FragmentUpload.this, 1);
            }
        });
    }

    private void resetFields(){
        UniversalImageLoader.setImage("", mUploadImage);
        mFileName.setText("");
        mDateOfUse.setText("");
        //check later and maybe change the set text
        mGrade.setText("");
        mClass.setText("");
        mReflection.setText("");

    }

    private void showProgressBar(){

        mProgressBar.setVisibility(View.VISIBLE);
    }

    private void hideProgressBar(){
        if(mProgressBar.getVisibility() == View.VISIBLE){
            mProgressBar.setVisibility(View.INVISIBLE);
        }
    }

    private boolean isEmpty(String string){
        return string.equals("");
    }


}

我不确定这可能是什么原因。我是否可能需要在通用图像加载器中添加不同的图像选项?任何帮助将不胜感激。

0 个答案:

没有答案