Example usage for android.widget ImageView setAdjustViewBounds

List of usage examples for android.widget ImageView setAdjustViewBounds

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setAdjustViewBounds(boolean adjustViewBounds) 

Source Link

Document

Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable.

Usage

From source file:org.wheelmap.android.activity.MainSinglePaneActivity.java

private void initMapSwitchListOptionsItem(final ImageView listMapToggle, final TextView title) {
    int switch_res = mSelectedTab == Constants.TabContent.LOCATION_BASED_LIST ? R.drawable.ic_map
            : R.drawable.ic_list;// w  ww .  j av  a2 s.co m
    listMapToggle.setImageResource(switch_res);
    listMapToggle.setAdjustViewBounds(true);
    OnClickListener l = new OnClickListener() {
        @Override
        public void onClick(View view) {
            mSelectedTab = mSelectedTab == Constants.TabContent.LOCATION_BASED_LIST ? Constants.TabContent.MAP
                    : Constants.TabContent.LOCATION_BASED_LIST;

            int switch_res = mSelectedTab == Constants.TabContent.LOCATION_BASED_LIST ? R.drawable.ic_map
                    : R.drawable.ic_list;
            int title_res = mSelectedTab == Constants.TabContent.LOCATION_BASED_LIST
                    ? R.string.dashboard_button_title_nearby
                    : R.string.dashboard_button_title_map;
            listMapToggle.setImageResource(switch_res);
            flipper.showNext();

            title.setText(title_res);

            AnalyticsTrackingManager.trackScreen(mSelectedTab == Constants.TabContent.LOCATION_BASED_LIST
                    ? AnalyticsTrackingManager.TrackableScreensName.NEARBYSCREEN
                    : AnalyticsTrackingManager.TrackableScreensName.MAPSCREEN);
        }
    };
    listMapToggle.setOnClickListener(l);
}

From source file:com.joravasal.comicagg.ComicDetailFragment.java

@SuppressLint({ "NewApi" })
@Override//from w  w w .j  a  v a2  s.c  o m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_comic_detail, container, false);
    if (comicItem == null && savedInstanceState.containsKey(ARG_ITEM_ID)) {
        comicItem = new ComicItem(savedInstanceState.getString(ARG_ITEM_ID),
                savedInstanceState.getString("comicname"), savedInstanceState.getString("comicurl"),
                savedInstanceState.getString("unreadcount"));
    }
    int unread = Integer.parseInt(comicItem.unreadCount);
    if (unread == 0) {
        rootView.findViewById(R.id.vote_bar).setVisibility(View.GONE);
    }
    LinearLayout stripList = (LinearLayout) rootView.findViewById(R.id.strips_list);
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

    if (comicItem.id.equals(ComicStripsContent.id) && ComicStripsContent.ITEMS.size() > unread) {
        unread = ComicStripsContent.ITEMS.size();
    }
    for (int i = 1; i < unread; i++) {
        ImageView iv = new ImageView(getActivity());
        iv.setId(Integer.MAX_VALUE - i);
        iv.setPadding(16, 16, 16, 0);
        iv.setContentDescription(getString(R.string.strip_description));
        iv.setAdjustViewBounds(true);

        iv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                // TODO check if there is need of opening? or always open?
                openFullscreenStrip(v);
            }
        });

        TextView tv = new TextView(getActivity());
        tv.setId(i);
        tv.setPadding(16, 4, 16, 4);
        tv.setGravity(Gravity.CENTER);

        stripList.addView(iv, layoutParams);
        stripList.addView(tv, layoutParams);
    }

    if (!comicItem.id.equals(ComicStripsContent.id)) {
        new GetComicsStrips(comicItem.id, unread, rootView).execute();
    } else {
        new GetComicsStrips(comicItem.id, unread, rootView).onPostExecute(null);
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(VERTICAL_SCROLLING_POSITION)
            && VERSION.SDK_INT >= 14) {
        rootView.findViewById(R.id.comic_scrollView).scrollTo(0,
                savedInstanceState.getInt(VERTICAL_SCROLLING_POSITION));
    }
    return rootView;
}

From source file:ca.ualberta.cs.swapmyride.View.AddInventoryActivity.java

/**
 * In this function (prescribed by Android), we collect all information
 * about the new vehicle and input it into a vehicle object.
 * This is then saved.//  ww  w. j  a  v a2s .c  o m
 *
 * @param savedInstanceState
 */

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.addinventory);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    uController = new UserController(getApplicationContext());
    // TODO: Needs to smell more MVCish
    //vehicleImage = (ImageButton) findViewById(R.id.vehicleImage);
    gallery = (LinearLayout) findViewById(R.id.addinventorygallery);
    delete = (Button) findViewById(R.id.delete);
    vehicleName = (EditText) findViewById(R.id.vehicleField);
    vehicleQuantity = (EditText) findViewById(R.id.quantityField);
    vehicleComments = (EditText) findViewById(R.id.commentsField);
    vehiclePublic = (Switch) findViewById(R.id.ispublic);
    done = (Button) findViewById(R.id.button);
    location = (EditText) findViewById(R.id.locationField);
    vehicle = new Vehicle();

    //Assign and display the current location
    geolocation = new Geolocation();
    try {
        current = geolocation.getCurrentLocation(getApplicationContext(), this);
        location.setText(current.getPostalCode());
    } catch (IllegalArgumentException e) {
        location.setText("Geolocation cannot be determined.");
    }

    /**
     * Using spinners to select category and quality of a vehicle - taking from the enumeration
     * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow
     * Accessed 2015-11-01
     * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a>
     */
    categorySpinner = (Spinner) findViewById(R.id.categorySpinner);
    categorySpinner.setAdapter(new ArrayAdapter<VehicleCategory>(this,
            android.R.layout.simple_spinner_dropdown_item, VehicleCategory.values()));
    categorySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            vehicleCategory = (VehicleCategory) categorySpinner.getSelectedItem();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // What if nothing selected?
        }
    });

    /**
     * Using spinners to select category and quality of a vehicle - taking from the enumeration
     * classes we have elsewhere. This function was adapted from Biraj Zalavadia on StackOverflow
     * Accessed 2015-11-01
     * @see <a href="http://stackoverflow.com/questions/21600781/onitemclicklistener-of-spinner">stackOverflow</a>
     */
    qualitySpinner = (Spinner) findViewById(R.id.qualitySpinner);
    qualitySpinner.setAdapter(new ArrayAdapter<VehicleQuality>(this,
            android.R.layout.simple_spinner_dropdown_item, VehicleQuality.values()));
    qualitySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
            vehicleQuality = (VehicleQuality) qualitySpinner.getSelectedItem();
        }

        @Override
        public void onNothingSelected(AdapterView<?> arg0) {
            // What if nothing selected?
        }
    });

    final boolean loadVehicle = getIntent().hasExtra("vehiclePosition");
    Vehicle loaded;
    if (loadVehicle) {
        position = getIntent().getIntExtra("vehiclePosition", 0);
        loaded = UserSingleton.getCurrentUser().getInventory().getList().get(position);

        //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE
        //load the picture from the first
        vehicle.setPhotoIds(loaded.getPhotoIds());

        vehicleName.setText(loaded.getName());
        vehicleQuantity.setText(loaded.getQuantity().toString());
        vehicleComments.setText(loaded.getComments());
        vehiclePublic.setChecked(loaded.getPublic());
        qualitySpinner.setSelection(loaded.getQuality().getPosition());
        categorySpinner.setSelection(loaded.getCategory().getPosition());
        // TODO: Fix null error issue
        //location.setText(loaded.getLocation().getPostalCode());
        LocalDataManager ldm = new LocalDataManager(getApplicationContext());
        for (UniqueID uid : vehicle.getPhotoIds()) {
            photos.add(ldm.loadPhoto(uid.getID()));
        }
        for (Photo photo : photos) {
            ImageView newImage = new ImageView(getApplicationContext());
            newImage.setImageBitmap(photo.getImage());
            newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            newImage.setAdjustViewBounds(true);
            gallery.addView(newImage);
        }

    }

    //default the photo to a new photo if we are not loading a vehicle
    else {
        // TODO: Default photo? Here or set in Vehicle?
        Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto();
        ImageView newImage = new ImageView(getApplicationContext());
        newImage.setImageBitmap(photo.getImage());
        newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        newImage.setAdjustViewBounds(true);
        gallery.addView(newImage);
        vehicle.deletePhotoArrayList(getApplicationContext());
    }

    LocalDataManager ldm = new LocalDataManager(getApplicationContext());

    //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE
    //load the picture from the first
    for (UniqueID uid : vehicle.getPhotoIds()) {
        Photo photo;
        if (UserSingleton.getDownloadPhotos()) {
            photo = ldm.loadPhoto(uid.getID());
        } else {
            photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto();
        }
        ImageView newImage = new ImageView(getApplicationContext());
        newImage.setImageBitmap(photo.getImage());
        newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        newImage.setAdjustViewBounds(true);
        gallery.addView(newImage);
    }
    /**
     * This onClick listener implements the function that clicking on the default
     * image box at the top of the vehicle page will open the camera and allow the
     * user to take a photo which will be saved directly to the vehicle object
     */
    gallery.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            dispatchTakePictureIntent();

        }
    });

    /**
     * This onClick listener occurs when someone clicks delete. This will delete the photo
     * that is initialized in the view.
     */
    delete.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //vehicle.setPhoto(new Photo(getApplicationContext()));
            //vehicleImage.setBackground(new BitmapDrawable(getResources(), vehicle.getPhoto().getImage()));
            vehicle.deletePhotoArrayList(getApplicationContext());
            gallery.removeAllViews();
            Photo photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto();
            ImageView newImage = new ImageView(getApplicationContext());
            newImage.setImageBitmap(photo.getImage());
            newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            newImage.setAdjustViewBounds(true);
            gallery.addView(newImage);
            LocalDataManager ldm = new LocalDataManager(getApplicationContext());
            for (Photo photo1 : photos) {
                ldm.deletePhoto(photo1.getUid().getID());
            }
            photos.clear();

            //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE
            //load the picture from the first
            if (vehicle.getPhotoIds().size() > 0 && UserSingleton.getDownloadPhotos()) {
                gallery.removeAllViews();
            }

            for (UniqueID uid : vehicle.getPhotoIds()) {
                if (UserSingleton.getDownloadPhotos()) {
                    photo = ldm.loadPhoto(uid.getID());
                }
                newImage = new ImageView(getApplicationContext());
                newImage.setImageBitmap(photo.getImage());
                newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                newImage.setAdjustViewBounds(true);
                gallery.addView(newImage);
            }
        }
    });

    /**
     * This onClick listener occurs after done button is clicked. This would save
     * the object to inventory -- which then makes it appear in the inventory tab.
     *
     * Taken from Oracle Documentation - we found we were required to catch the
     * possibility that a number might be the wrong format, or not even a number
     * at all. Accessed November 3, 2015.
     *
     * @see <a href="http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int-">Oracle</a>
     */

    done.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // vehicle.setPhoto(vehicleImage);
            Geolocation geolocation1 = new Geolocation();
            LocalDataManager ldm = new LocalDataManager(getApplicationContext());

            if (vehicleName.getText().toString().equals("")) {
                Toast.makeText(AddInventoryActivity.this, "Please enter name", Toast.LENGTH_SHORT).show();
                return;
            }

            if (vehicleQuantity.getText().toString().equals("0")
                    || vehicleQuantity.getText().toString().equals("")) {
                Toast.makeText(AddInventoryActivity.this, "Quantity cannot be 0", Toast.LENGTH_SHORT).show();
                return;
            }
            vehicle.setName(vehicleName.getText().toString());

            vehicle.setCategory(vehicleCategory);
            vehicle.setQuality(vehicleQuality);
            vehicle.setLocation(geolocation1.setSpecificLocation(getApplicationContext(),
                    AddInventoryActivity.this, location.getText().toString()));

            //http://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html#parseInt-java.lang.String-int-
            //Nov. 3/ 2015
            //the error should never occur as we force the user to input a numeric value, but
            //we are required to catch it anyway
            try {
                vehicle.setQuantity(Integer.parseInt(vehicleQuantity.getText().toString()));
            } catch (NumberFormatException e) {
                e.printStackTrace();
            }
            vehicle.setComments(vehicleComments.getText().toString());
            vehicle.setPublic(vehiclePublic.isChecked());
            vehicle.setBelongsTo(UserSingleton.getCurrentUser().getUserName());

            for (Photo photo : photos) {
                vehicle.addPhoto(photo.getUid());
                ldm.savePhoto(photo);
            }

            //add the vehicle to our current user.
            if (loadVehicle) {
                //UserSingleton.getCurrentUser().getInventory().getList().add(position, vehicle);
                uController.getUserInventoryItems().add(position, vehicle);
                //UserSingleton.getCurrentUser().getInventory().getList().remove(position+1);
                uController.getUserInventoryItems().remove(position + 1);
            } else {
                //UserSingleton.getCurrentUser().addItem(vehicle);
                uController.getCurrentUser().addItem(vehicle);
            }
            //save the user to ensure all changes are updated
            uController.saveCurrentUser();
            Gson gson = new Gson();
            String s = gson.toJson(vehicle);
            Log.i("SizeOfCar", Integer.toString(s.length()));

            /*
            //dont start a new activity if we are editing a vehicle
            if(!loadVehicle) {
            Intent intent = new Intent(AddInventoryActivity.this, MainMenu.class);
            startActivity(intent);
            }*/
            finish();
        }
    });

    gallery.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            vehicle.deletePhotoArrayList(getApplicationContext());
            gallery.removeAllViews();
            LocalDataManager ldm = new LocalDataManager(getApplicationContext());

            //TODO UPDATE THIS LINE TO UPDATE THE FEED WITH THE VEHICLES FIRST PICTURE
            //load the picture from the first
            for (UniqueID uid : vehicle.getPhotoIds()) {
                Photo photo;
                if (UserSingleton.getDownloadPhotos()) {
                    photo = ldm.loadPhoto(uid.getID());
                } else {
                    photo = DefaultPhotoSingleton.getInstance().getDefaultPhoto();
                }
                ImageView newImage = new ImageView(getApplicationContext());
                newImage.setImageBitmap(photo.getImage());
                newImage.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
                newImage.setAdjustViewBounds(true);
                gallery.addView(newImage);
            }
            return true;
        }
    });

}

From source file:com.ushahidi.android.app.ui.phone.AddReportActivity.java

@Override
public View makeView() {
    ImageView i = new ImageView(this);
    i.setAdjustViewBounds(true);
    i.setScaleType(ImageView.ScaleType.FIT_CENTER);
    i.setLayoutParams(new ImageSwitcher.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT));

    return i;//from  w ww. j a v a  2  s  .co m
}

From source file:edu.cmu.cylab.starslinger.view.SlingerFragment.java

private void drawContactData(TextView textViewUserName, ListView listViewContactFields,
        ImageView imageViewPhoto) {
    // order: name, photo, phone, im, email, url, postal, title, org

    // make sure view is already inflated...
    if (listViewContactFields == null) {
        return;/*from   w ww . j  av a2  s  .  c o m*/
    }

    mContactFields = new ArrayList<ContactField>();
    ContactFieldAdapter mAdapter;

    // draw name
    if (mContact.name != null && !TextUtils.isEmpty(mContact.name.toString())) {
        textViewUserName.setText(mContact.name.toString());
    } else {
        textViewUserName.setText("");
    }

    // draw photo
    imageViewPhoto.setBackgroundColor(Color.TRANSPARENT);
    try {
        if (mContact.photoBytes != null) {
            Bitmap bm = BitmapFactory.decodeByteArray(mContact.photoBytes, 0, mContact.photoBytes.length, null);
            imageViewPhoto.setImageBitmap(bm);
            imageViewPhoto.setAdjustViewBounds(true);

            mContactFields.add(new ContactField( //
                    R.drawable.ic_ks_photo, //
                    getString(R.string.label_Photo), //
                    ""));
        } else {
            imageViewPhoto.setImageDrawable(getResources().getDrawable(R.drawable.ic_silhouette));
        }
    } catch (OutOfMemoryError e) {
        imageViewPhoto.setImageDrawable(null);
    }

    // draw from phones
    if (mContact.phoneList != null)
        for (PhoneData m : mContact.phoneList) {

            mContactFields.add(new ContactField( //
                    R.drawable.ic_ks_phone, //
                    getPhoneTypeLabel(m.type, m.label), //
                    m.data));
        }

    // draw from contact methods
    if (mContact.contactmethodList != null) {

        // ims
        for (ContactMethod i : mContact.contactmethodList) {
            switch (i.kind) {
            case Contacts.KIND_IM:

                boolean isCustom = (i.kind == Contacts.KIND_IM) && mAccessor.isCustomIm(i.label);
                String data = i.data;
                String typeDisplay = "";
                int iconid = 0;
                boolean forceCheck = false;

                if (isCustom) {
                    iconid = R.drawable.ic_ks_key;
                    data = i.label;
                    typeDisplay = "";
                    forceCheck = true;
                } else {
                    iconid = R.drawable.ic_ks_im;
                    typeDisplay = mAccessor.getDesc(i.kind, i.type, i.label);
                }

                mContactFields.add(new ContactField( //
                        iconid, //
                        typeDisplay, //
                        delimitedString(data), forceCheck));
                break;
            default:
                break;
            }
        }

        // emails
        for (ContactMethod e : mContact.contactmethodList) {
            switch (e.kind) {
            case Contacts.KIND_EMAIL:
                String data = e.data;
                String typeDisplay = "";
                int iconid = 0;
                boolean forceCheck = false;

                iconid = R.drawable.ic_ks_email;
                typeDisplay = getEmailTypeLabel(e.type, e.label);

                mContactFields.add(new ContactField( //
                        iconid, //
                        typeDisplay, //
                        delimitedString(data), forceCheck));
                break;
            default:
                break;
            }
        }

        // urls
        for (ContactMethod u : mContact.contactmethodList) {
            switch (u.kind) {
            case Contacts.KIND_URL:

                String data = u.data;
                String typeDisplay = "";
                int iconid = 0;
                boolean forceCheck = false;

                iconid = R.drawable.ic_ks_url;

                mContactFields.add(new ContactField( //
                        iconid, //
                        typeDisplay, //
                        delimitedString(data), forceCheck));
                break;
            default:
                break;
            }
        }
    }

    // draw from addresses
    if (mContact.addressList != null)
        for (Address m : mContact.addressList) {

            mContactFields.add(new ContactField( //
                    R.drawable.ic_ks_postal, //
                    getStructuredPostalTypeLabel(m.getType(), m.getLabel()), //
                    delimitedString(m.toString())));
        }

    mAdapter = new ContactFieldAdapter(getActivity(), mContactFields);
    listViewContactFields.setAdapter(mAdapter);

    // restore list position
    listViewContactFields.setSelectionFromTop(mListVisiblePos, mListTopOffset);
}

From source file:com.hichinaschool.flashcards.anki.multimediacard.activity.MultimediaCardEditorActivity.java

private void createNewViewer(LinearLayout linearLayout, final IField field, final int index) {

    final MultimediaCardEditorActivity context = this;

    switch (field.getType()) {
    case TEXT:/*from   w w w. ja  v a 2 s. c  om*/

        // Create a text field and an edit button, opening editing for
        // the
        // text field

        TextView textView = new TextView(this);
        textView.setText(field.getText());
        linearLayout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT);

        break;

    case IMAGE:

        ImageView imgView = new ImageView(this);
        //
        // BitmapFactory.Options options = new BitmapFactory.Options();
        // options.inSampleSize = 2;
        // Bitmap bm = BitmapFactory.decodeFile(myJpgPath, options);
        // jpgView.setImageBitmap(bm);

        LinearLayout.LayoutParams p = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);

        File f = new File(field.getImagePath());

        Bitmap b = BitmapUtil.decodeFile(f, getMaxImageSize());

        int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentapiVersion >= android.os.Build.VERSION_CODES.ECLAIR) {
            b = ExifUtil.rotateFromCamera(f, b);
        }

        imgView.setImageBitmap(b);

        imgView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imgView.setAdjustViewBounds(true);

        DisplayMetrics metrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metrics);

        int height = metrics.heightPixels;
        int width = metrics.widthPixels;

        imgView.setMaxHeight((int) Math.round(height * 0.6));
        imgView.setMaxWidth((int) Math.round(width * 0.7));
        linearLayout.addView(imgView, p);

        break;
    case AUDIO:
        AudioView audioView = AudioView.createPlayerInstance(this, R.drawable.av_play, R.drawable.av_pause,
                R.drawable.av_stop, field.getAudioPath());
        linearLayout.addView(audioView);
        break;

    default:
        Log.e("multimedia editor", "Unsupported field type found");
        break;
    }

    Button editButtonText = new Button(this);
    editButtonText.setText(gtxt(R.string.multimedia_editor_activity_edit_button));
    linearLayout.addView(editButtonText, LinearLayout.LayoutParams.MATCH_PARENT);

    editButtonText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent i = new Intent(context, EditFieldActivity.class);
            putExtrasAndStartEditActivity(field, index, i);
        }

    });
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private RelativeLayout createParticipantView(MemberStatusTO ms) {
    RelativeLayout rl = new RelativeLayout(this);
    int rlW = UIUtils.convertDipToPixels(this, 55);
    rl.setLayoutParams(new RelativeLayout.LayoutParams(rlW, rlW));

    getLayoutInflater().inflate(R.layout.avatar, rl);
    ImageView avatar = (ImageView) rl.getChildAt(rl.getChildCount() - 1);
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(avatar.getLayoutParams());
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    params.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
    avatar.setLayoutParams(params);/*  ww  w .ja  va  2  s.c  om*/
    setAvatar(avatar, ms.member);

    ImageView statusView = new ImageView(this);
    int w = UIUtils.convertDipToPixels(this, 12);
    RelativeLayout.LayoutParams iconParams = new RelativeLayout.LayoutParams(w, w);
    iconParams.addRule(RelativeLayout.ALIGN_PARENT_TOP, RelativeLayout.TRUE);
    iconParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    statusView.setLayoutParams(iconParams);
    statusView.setAdjustViewBounds(true);
    statusView.setScaleType(ScaleType.CENTER_CROP);
    setStatusIcon(statusView, ms);
    rl.addView(statusView);
    return rl;
}

From source file:cl.gisred.android.PowerOnActivity.java

private void abrirLeyenda() {
    ImageView image = new ImageView(this);
    image.setImageResource(R.drawable.leyenda_power);
    image.setAdjustViewBounds(true);

    AlertDialog.Builder builder = new AlertDialog.Builder(this)
            .setPositiveButton("CERRAR", new DialogInterface.OnClickListener() {
                @Override//from w ww .j av  a2 s  . c o m
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            }).setView(image);

    builder.create().show();
}

From source file:cl.gisred.android.InspActivity.java

private void eliminarImg(ImageView img) {

    if (Build.VERSION.SDK_INT < 23)
        img.setAdjustViewBounds(true);
    //img.setImageResource(android.R.color.transparent);
    img.setImageDrawable(null);//  ww  w .  j a  va 2  s  .  c o  m

    Toast.makeText(getApplicationContext(), "Eliminado", Toast.LENGTH_SHORT).show();
}