Example usage for android.widget ImageView setScaleType

List of usage examples for android.widget ImageView setScaleType

Introduction

In this page you can find the example usage for android.widget ImageView setScaleType.

Prototype

public void setScaleType(ScaleType scaleType) 

Source Link

Document

Controls how the image should be resized or moved to match the size of this ImageView.

Usage

From source file:com.imagersliderlib.adapter.ImagePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup view, int position) {
    View imageLayout = inflater.inflate(R.layout.image_pager_layout, view, false);
    assert imageLayout != null;
    ImageView imageView = (ImageView) imageLayout.findViewById(R.id.image);

    // image loding progressbar
    final ProgressBar spinner = (ProgressBar) imageLayout.findViewById(R.id.loading);

    // image scale set
    imageView.setScaleType(ScaleType.FIT_XY);

    // init ImageLoader
    imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(mContext));

    // ImageLoader set option
    options = new DisplayImageOptions.Builder().showImageForEmptyUri(new ColorDrawable(0xff6e6e6e))
            .showImageOnFail(new ColorDrawable(0xff6e6e6e)).showImageOnLoading(new ColorDrawable(0xff6e6e6e))
            .cacheInMemory(true).cacheOnDisk(true).build();

    imageLoader.displayImage(mImages.get(position), imageView, options, new SimpleImageLoadingListener() {
        @Override//from w  w  w .  j  av  a2s  . co  m
        public void onLoadingStarted(String imageUri, View view) {
            spinner.setVisibility(View.VISIBLE);
        }

        @Override
        public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
            String message = null;
            switch (failReason.getType()) {
            case IO_ERROR:
                message = "Input/Output error";
                break;
            case DECODING_ERROR:
                message = "Image can't be decoded";
                break;
            case NETWORK_DENIED:
                message = "Downloads are denied";
                break;
            case OUT_OF_MEMORY:
                message = "Out Of Memory error";
                break;
            case UNKNOWN:
                message = "Unknown error";
                break;
            }
            Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();

            spinner.setVisibility(View.GONE);
        }

        @Override
        public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
            spinner.setVisibility(View.GONE);
        }
    });

    view.addView(imageLayout, 0);
    return imageLayout;
}

From source file:com.cleanwiz.applock.ui.activity.AppLockActivity.java

private void initPoints(int pagers) {
    pLayout.removeAllViews();//  w ww. j av a  2s.c  om
    points = new ArrayList<ImageView>();
    int maxW = ScreenUtil.dip2px(mContext, 24);
    int width = Math.min(maxW, pLayout.getWidth() / pagers);
    int height = ScreenUtil.dip2px(mContext, 16);
    for (int i = 0; i < pagers; i++) {
        ImageView iv = new ImageView(mContext);
        iv.setScaleType(ScaleType.CENTER_INSIDE);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(width, height);
        if (i == 0) {
            iv.setImageResource(R.drawable.pager_point_white);
        } else {
            iv.setImageResource(R.drawable.pager_point_green);
        }
        pLayout.addView(iv, lp);
        points.add(iv);
    }

}

From source file:android.support.v17.leanback.widget.DetailsOverviewSharedElementHelper.java

private void changeImageViewScale(View snapshotView) {
    ImageView snapshotImageView = (ImageView) snapshotView;
    ImageView imageView = mViewHolder.mImageView;
    if (DEBUG) {/*from  w  w w  . j av a2 s .c o  m*/
        Log.d(TAG, "changeImageViewScale to " + snapshotImageView.getScaleType());
    }
    imageView.setScaleType(snapshotImageView.getScaleType());
    if (snapshotImageView.getScaleType() == ScaleType.MATRIX) {
        imageView.setImageMatrix(snapshotImageView.getImageMatrix());
    }
    updateImageViewAfterScaleTypeChange(imageView);
}

From source file:info.papdt.blacklight.ui.common.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.// ww w  .  j  ava 2 s  . c o m
 */
protected View createDefaultTabView(Context context) {
    View v;
    if (mIconAdapter == null) {
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        textView.setTypeface(Typeface.DEFAULT_BOLD);
        textView.setAllCaps(true);
        textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        int padding = (int) (TAB_TEXT_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        textView.setPadding(padding, padding, padding, padding);

        v = textView;
    } else {
        ImageView imgView = new TintImageView(context);
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setLayoutParams(new LinearLayout.LayoutParams(mTabIconSize, mTabIconSize));

        v = imgView;
    }

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    if (v instanceof ImageView) {
        v.setBackgroundResource(outValue.resourceId);
        int padding = (int) (TAB_ICON_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        v.setPadding(padding, padding, padding, padding);
    }

    return v;
}

From source file:com.dreamspace.superman.UI.View.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from  www  .  j  a  va2s  . c om*/
 */
protected View createDefaultTabView(Context context) {
    View v;
    if (mIconAdapter == null) {
        TextView textView = new TextView(context);
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
        textView.setTypeface(Typeface.DEFAULT);
        textView.setAllCaps(true);
        textView.setTextColor(getStartColor());
        if (fillTheWidth) {
            textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 1));
        } else {
            textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                    ViewGroup.LayoutParams.MATCH_PARENT));

        }
        ;

        v = textView;
    } else {
        ImageView imgView = new TintImageView(context);
        imgView.setScaleType(ImageView.ScaleType.FIT_XY);
        imgView.setLayoutParams(new LinearLayout.LayoutParams(mTabIconSize, mTabIconSize));
        v = imgView;
    }

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    v.setBackgroundResource(outValue.resourceId);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    v.setPadding(padding, padding, padding, padding);

    return v;
}

From source file:uk.co.senab.photoview.PhotoViewAttacher.java

/**
 * Set's the ImageView's ScaleType to Matrix.
 *///from  www  .j a va2s.com
private static void setImageViewScaleTypeMatrix(ImageView imageView) {
    /**
     * PhotoView sets it's own ScaleType to Matrix, then diverts all calls
     * setScaleType to this.setScaleType automatically.
     */
    if (null != imageView) {
        if (!ScaleType.MATRIX.equals(imageView.getScaleType())) {
            imageView.setScaleType(ScaleType.MATRIX);
        }
    }
}

From source file:com.example.meetingapp.ShowDetailsFragment.java

/**
 * Adds an image to the HorizontalScrollView.
 * @param image Image to be added to the HorizontalScrollView.
 */// ww w  .j a  v  a  2 s.c o  m
private void addImage(Bitmap image) {
    LinearLayout layout = new LinearLayout(getActivity());
    layout.setGravity(Gravity.CENTER);

    /* Set parameters - we want a small divider of 3 pixels so we can
     * easily distinguish different photos.
     */
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.setMargins(3, 0, 0, 0);
    params.gravity = Gravity.CENTER;

    ImageView imageView = new ImageView(getActivity());
    imageView.setScaleType(ScaleType.CENTER);
    imageView.setImageBitmap(image);
    imageView.setLayoutParams(params);

    layout.addView(imageView);
    mPhotosView.addView(layout);
}

From source file:gov.nasa.arc.geocam.geocam.CameraPreviewActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Window and view properties
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    setContentView(R.layout.camera_preview);

    // Load bitmap from intent data and display in imageview
    mImageUri = getIntent().getData();//  w w  w  .  ja v a2 s  .  c o m
    try {
        mImageData = new JSONObject(getIntent().getExtras().getString("data"));
    } catch (JSONException e1) {
        Log.d(GeoCamMobile.DEBUG_ID, "Error unserializing JSON data from intent");
        mImageData = new JSONObject();
    }

    try {
        final BitmapFactory.Options opts = new BitmapFactory.Options();
        opts.inSampleSize = 4;
        InputStream in = getContentResolver().openInputStream(mImageUri);
        Bitmap bitmap = BitmapFactory.decodeStream(in, null, opts);

        //Bitmap bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), mImageUri);
        ImageView imageView = (ImageView) findViewById(R.id.camera_preview_imageview);
        imageView.setAdjustViewBounds(true);
        imageView.setScaleType(ScaleType.CENTER_INSIDE);
        imageView.setImageBitmap(bitmap);
    } catch (FileNotFoundException e) {
        Log.d(GeoCamMobile.DEBUG_ID, "Error loading bitmap in CameraPreviewActivity");
    }

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
    String defaultNotes = settings.getString(GeoCamMobile.SETTINGS_DEFAULT_NOTES_KEY, "");

    // Set default notes
    EditText notesText = (EditText) findViewById(R.id.camera_preview_edittext);
    notesText.setText(defaultNotes + " ");

    // Buttons
    mFireButton = (ImageButton) findViewById(R.id.camera_preview_fire_button);
    mFireButton.setImageDrawable(getResources().getDrawable(R.drawable.fire_icon_default));
    mFireButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_PICK);
            intent.setClass(CameraPreviewActivity.this, FireIconActivity.class);
            startActivityForResult(intent, PICK_ICON_REQUEST);
        }
    });

    final ImageButton deleteButton = (ImageButton) findViewById(R.id.camera_preview_delete_button);
    deleteButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            CameraPreviewActivity.this.showDialog(DIALOG_DELETE_PHOTO);
        }
    });

    final ImageButton saveButton = (ImageButton) findViewById(R.id.camera_preview_save_button);
    saveButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            mImageNote = ((EditText) findViewById(R.id.camera_preview_edittext)).getText().toString();
            Log.d(GeoCamMobile.DEBUG_ID, "Setting image note to: " + mImageNote);
            saveWithAnnotation();
        }
    });

    mForeground = new ForegroundTracker(this);
}

From source file:com.chillax.viewpagerindicator.IconPageIndicator.java

public void notifyDataSetChanged() {
    mIconsLayout.removeAllViews();//from  w  w w .j  a  v  a2 s  . c  o  m
    IconPagerAdapter iconAdapter = (IconPagerAdapter) mViewPager.getAdapter();
    int count = iconAdapter.getCount();
    int padding = ScreenUtil.dp2px(context, 10);
    for (int i = 0; i < count; i++) {
        ImageView view = new ImageView(getContext());
        view.setLayoutParams(
                new ViewGroup.LayoutParams(ScreenUtil.dp2px(context, 35), ScreenUtil.dp2px(context, 35)));
        view.setPadding(padding, padding, padding, padding);
        view.setScaleType(ImageView.ScaleType.FIT_XY);
        view.setImageResource(R.drawable.leader_icon);
        mIconsLayout.addView(view);
    }
    if (mSelectedIndex > count) {
        mSelectedIndex = count - 1;
    }
    setCurrentItem(mSelectedIndex);
    requestLayout();
}

From source file:com.wlzndjk.poker.widget.MyHScrollView.java

private void addImageTab(final int position, String title) {

    ImageView tab = new ImageView(getContext());
    tab.setImageResource(tabDatas.get(position));
    tab.setScaleType(ImageView.ScaleType.FIT_XY);
    addTab(position, tab);//www .j  a v  a 2s  .c  o m
}