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:edu.ucsb.cs.cs185.inspirante.collectiondetails.CollectionDetailsActivity.java

protected void startDetailDialog(int position) {
    Bundle arguments = new Bundle();
    arguments.putInt("CARD_INDEX", mCardIndex);
    arguments.putInt("IMAGE_INDEX", position);

    arguments.putString("FROM", "DETAILS");
    DetailBlurDialog fragment = new DetailBlurDialog();

    fragment.setArguments(arguments);//  ww  w .  j a v  a  2 s  .co  m
    FragmentManager ft = this.getSupportFragmentManager();

    fragment.show(ft, "dialog");
    //TODO: move takeScreenShot method to somewhere else from CardsFragment

    Bitmap map = CardsFragment.takeScreenShot(this);
    Bitmap fast = CardsFragment.BlurBuilder.blur(getApplicationContext(), map);
    final Drawable draw = new BitmapDrawable(getResources(), fast);

    ImageView background = (ImageView) findViewById(R.id.activity_background);
    background.bringToFront();
    background.setScaleType(ImageView.ScaleType.FIT_XY);
    background.setImageDrawable(draw);
}

From source file:org.jraf.android.hellomundo.app.pickwebcam.PickWebcamListFragment.java

private View getHeaderView(ListView listView) {
    View res = getActivity().getLayoutInflater().inflate(R.layout.pick_webcam_item, listView, false);
    ImageView imgThumbnail = (ImageView) res.findViewById(R.id.imgThumbnail);
    imgThumbnail.setImageResource(R.drawable.ic_random_thumbnail);
    imgThumbnail.setScaleType(ScaleType.FIT_CENTER);
    res.findViewById(R.id.btnExtend).setVisibility(View.GONE);
    ((TextView) res.findViewById(R.id.txtName)).setText(R.string.pickWebcam_random_title);
    ((TextView) res.findViewById(R.id.txtLocationAndTime)).setText(R.string.pickWebcam_random_subtitle);

    if (mCurrentWebcamId == Constants.WEBCAM_ID_RANDOM) {
        res.findViewById(R.id.conMainItem).setSelected(true);
    }/*from ww  w. j av  a 2s  .c o m*/
    return res;
}

From source file:com.google.android.apps.santatracker.dasherdancer.CharacterAdapter.java

@Override
public Object instantiateItem(ViewGroup container, int position) {
    ImageView view = null;

    if (position < mCharacters.length) {
        if (mViews.get(position) != null) {
            view = mViews.get(position);
        } else {/*  w  w w .ja  v  a2s .c om*/
            view = new FrameAnimationView(container.getContext());
            view.setScaleType(ImageView.ScaleType.CENTER_CROP);
            //Load the first idle frame.
            view.setBackgroundResource(mBackgrounds[position]);
            view.setTag(position);
            mViews.put(position, view);
        }

        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        container.addView(view, lp);
    }

    return view;
}

From source file:com.chrslee.csgopedia.app.CardFragment.java

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

    //Looks like he did this layout via code this is a layoutparams object
    //it defines the metrics and bounds of a specific view
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    //Creating a FrameLayout a FrameLayout is basically a empty container
    FrameLayout fl = new FrameLayout(context);
    fl.setLayoutParams(params);/*from ww  w.  j a v a 2  s. co  m*/
    //setting the params from above

    // First - image section
    //Building the imageview via code
    LayoutParams imgParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    imgParams.gravity = Gravity.CENTER;
    //setting all centered
    ImageView iv = new ImageView(context);
    iv.setLayoutParams(imgParams);
    iv.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    iv.setAdjustViewBounds(true);
    iv.setBackgroundResource(getActivity().getIntent().getExtras().getInt("iconID"));
    //seting the iconID as the image of this imageView

    // Second - prices section
    //final int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, getResources()
    //        .getDisplayMetrics());
    //

    //LinearLayout is another container it just take the
    //widgets inside it and display them in a linear order
    LinearLayout linLayout = new LinearLayout(context);
    linLayout.setOrientation(LinearLayout.VERTICAL);
    linLayout.setLayoutParams(params);
    linLayout.setGravity(Gravity.CENTER);

    // Get prices
    ConnectionDetector cd = new ConnectionDetector(context); //creating a connection detector to check for internet
    String query = getActivity().getIntent().getStringExtra("searchQuery"); //taking the name or whatever he pass from mainactivity from the searchquery arg
    TextView placeholder = new TextView(context); ///this is a textview for the name of the item
    if (cd.isConnectedToInternet()) {//if its connected to internet then
        if (query.equals("-1")) {//if the skin is regular he display is not for sale
            placeholder.setText("Regular skins are not for sale!");
            linLayout.addView(placeholder);
        } else {//else he calls the scrappperAsyncTask with the query
            new ScraperAsyncTask(linLayout).execute(query);
        }
    } else {//if its not connected he display the message here
        placeholder.setText("Please connect to the Internet to view prices.");
        linLayout.addView(placeholder);
    }

    //here he defines which tab he is displaying, Now I see why he used the same fragment,
    //this is a bad practice, he created both widgets before but just displays one of them
    //for each case if its the first tab he display the image if its the second the prices
    if (position == 0) {
        fl.addView(iv);
    } else {
        fl.addView(linLayout);
    }

    //Then he returns the framelayout (container) to display it in the screen
    return fl;
}

From source file:com.cmput301.recipebot.ui.adapters.ImagePagerAdapter.java

@Override
public Object instantiateItem(ViewGroup view, int position) {
    final ImageView imageView = new ImageView(mContext);
    String image = mImages.get(position);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    imageView.setLayoutParams(lp);/*w w w . java  2s .c o m*/
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    if (image.startsWith("http")) {
        ImageLoader.getInstance().displayImage(image, imageView);
    } else {
        new BitmapUtils.DecodeBitmapTask(imageView).execute(image);
    }
    ((ViewPager) view).addView(imageView, 0);
    return imageView;
}

From source file:ca.cmput301f13t03.adventure_datetime.view.FragmentView.java

public void setUpView() {
    if (_fragment == null)
        return;/*  w  ww  .  j  a  v a2s .c  o m*/

    /** Layout items **/
    _filmLayout = (LinearLayout) _rootView.findViewById(R.id.filmstrip);
    _filmstrip = (HorizontalScrollView) _rootView.findViewById(R.id.filmstrip_wrapper);
    _choices = (Button) _rootView.findViewById(R.id.choices);
    _content = (TextView) _rootView.findViewById(R.id.content);

    if (_fragment.getStoryMedia() == null)
        _fragment.setStoryMedia(new ArrayList<Image>());

    /* Run on UI Thread for server stuff */
    getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {

            /** Programmatically set filmstrip height **/
            if (_fragment.getStoryMedia().size() > 0)
                _filmstrip.getLayoutParams().height = FILM_STRIP_SIZE;
            else
                _filmstrip.getLayoutParams().height = 0;

            _content.setText(_fragment.getStoryText());
            _filmLayout.removeAllViews();

            // 1) Create new ImageView and add to the LinearLayout
            // 2) Set appropriate Layout Params to ImageView
            // 3) Give onClickListener for going to fullscreen
            LinearLayout.LayoutParams lp;
            //for (int i = 0; i < _fragment.getStoryMedia().size(); i++) {
            for (int i = 0; i < _fragment.getStoryMedia().size(); i++) {

                ImageView li = new ImageView(getActivity());
                li.setScaleType(ScaleType.CENTER_INSIDE);
                li.setImageBitmap(_fragment.getStoryMedia().get(i).decodeBitmap());
                _filmLayout.addView(li);

                lp = (LinearLayout.LayoutParams) li.getLayoutParams();
                lp.setMargins(10, 10, 10, 10);
                lp.width = FILM_STRIP_SIZE;
                lp.height = FILM_STRIP_SIZE;
                lp.gravity = Gravity.CENTER_VERTICAL;
                li.setLayoutParams(lp);

                li.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), FullScreen_Image.class);
                        intent.putExtra(FullScreen_Image.TAG_AUTHOR, false);
                        startActivity(intent);
                    }
                });
            }

            if (_fragment.getChoices().size() > 0) {
                /** Choices **/
                final List<String> choices = new ArrayList<String>();
                for (Choice choice : _fragment.getChoices())
                    choices.add(choice.getText());
                choices.add("I'm feeling lucky.");

                _choices.setText("Actions");
                _choices.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        new AlertDialog.Builder(v.getContext()).setTitle("Actions").setCancelable(true)
                                .setItems(choices.toArray(new String[choices.size()]),
                                        new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int which) {

                                                /** You feeling lucky, punk? **/
                                                if (which == _fragment.getChoices().size())
                                                    which = (int) (Math.random()
                                                            * _fragment.getChoices().size());

                                                Choice choice = _fragment.getChoices().get(which);

                                                Toast.makeText(FragmentView.this.getActivity(),
                                                        choice.getText(), Toast.LENGTH_LONG).show();
                                                Locator.getUserController().MakeChoice(choice);
                                            }
                                        })
                                .create().show();
                    }
                });
            } else {
                /** End of story **/
                Locator.getUserController().deleteBookmark();
                _choices.setText("The End");
                _choices.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        new AlertDialog.Builder(v.getContext()).setTitle("La Fin").setCancelable(true)
                                .setPositiveButton("Play Again", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        Locator.getUserController().StartStory(_fragment.getStoryID());
                                    }
                                })
                                .setNegativeButton("Change Adventures", new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (!_isEditing)
                                            getActivity().onBackPressed();
                                    }
                                }).create().show();

                    }
                });
            }
        }
    });

}

From source file:com.jasonchen.microlang.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  av a 2s. 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));

        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.ac.ucl.excites.sapelli.collector.ui.items.ImageItem.java

@Override
protected View createView(Context context, boolean recycleChildren) {
    ImageView view = new ImageView(context);

    // Set scaling (raster-based images are only scaled down, never up; vector-based ones can be scaled up or down):
    view.setScaleType(isVectorBased() ? (keepVectorAspectRatio ? ScaleType.FIT_CENTER : ScaleType.FIT_XY)
            : ScaleType.CENTER_INSIDE);// w w w  .  j a  v a2 s .c om

    /* Disable h/w acceleration for vector (SVG) images
     * Reason explained here:
     *  - https://github.com/japgolly/svg-android/commit/a1a613b
     *  - http://stackoverflow.com/q/10384613/1084488 */
    if (isVectorBased())
        ViewCompat.setLayerType(view, ViewCompat.LAYER_TYPE_SOFTWARE, null);

    // Set image:
    try {
        if (!isVectorBased()) { // Raster image (PNG, JPG, GIF, ...):
            if (file != null)
                view.setImageBitmap(BitmapUtils.loadBitmap(context, file)); // use BitmapUtils for memory-safe load of (potentially very large) image
            else
                view.setImageResource(drawableResourceID);
        } else { // Vector image (SVG or SVGZ):
                 //    Using svg-android lib:
                 /*view.setImageDrawable(new SVGDrawable((file != null ?
                    new SVGBuilder().readFromInputStream(new FileInputStream(file)) :
                    new SVGBuilder().readFromResource(context.getResources(), drawableResourceID)).build()));*/
                 //    Using AndroidSVG lib:
            view.setImageDrawable(
                    new PictureDrawable((file != null ? SVG.getFromInputStream(new FileInputStream(file))
                            : SVG.getFromResource(context.getResources(), drawableResourceID))
                                    .renderToPicture()));
        }
    } catch (Exception e) {
        Log.e(TAG, "Could not load image from " + (file != null ? "file" : "drawable resource") + "("
                + (file != null ? file.getAbsolutePath() : "id: " + drawableResourceID) + ")", e);
    }

    return view;
}

From source file:galilei.kelimekavanozu.view.ImageAdapter.java

@Override
public Object instantiateItem(ViewGroup container, final int position) {
    if (context.get() != null) {
        final int drawableId = theme.getImageList().get(position + 1);
        final ImageView view = new ImageView(context.get());
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        view.setContentDescription(context.get().getResources().getString(R.string.content_desc_poempic));
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setAdjustViewBounds(true);/* w w  w  . j  a v  a2 s.c o m*/
        view.setTag(drawableId);
        container.addView(view, 0);
        view.post(new Runnable() {
            @Override
            public void run() {
                ImageLoader.getImageLoader().load(drawableId, view);
            }
        });
        return view;
    }
    return null;
}

From source file:com.sinelead.car.club.map.AMapEx.java

@Override
public View makeView() {
    ImageView iv = new ImageView(context);
    iv.setScaleType(ImageView.ScaleType.CENTER);
    iv.setLayoutParams(new ImageSwitcher.LayoutParams(ImageSwitcher.LayoutParams.MATCH_PARENT,
            ImageSwitcher.LayoutParams.MATCH_PARENT));
    return iv;//  ww  w.  j ava2 s  . c  o  m
}