Example usage for android.widget ImageView setLayoutParams

List of usage examples for android.widget ImageView setLayoutParams

Introduction

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

Prototype

public void setLayoutParams(ViewGroup.LayoutParams params) 

Source Link

Document

Set the layout parameters associated with this view.

Usage

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Set the icon on the alert//w ww. ja v  a 2 s. co m
 *
 * @param context       application-specific resources
 * @param configuration describes all device configuration information
 * @param mainView      ViewGroup resources
 * @param textView      alert message to be viewed message to be displayedView
 */
@SuppressLint("NewApi")
private static void setIcon(Activity context, Configuration configuration, ViewGroup mainView,
        TextView textView) {

    ImageView imageView = (ImageView) mainView.findViewById(R.id.alert_view_icon);

    // Reset the current icon
    if (imageView != null) {
        mainView.removeView(imageView);
    }

    // On the textview as well
    textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
    textView.setCompoundDrawablePadding(0);

    if (configuration.getIconResId() != -1) {

        imageView = new ImageView(context);
        imageView.setId(R.id.alert_view_icon);

        imageView.setImageResource(configuration.getIconResId());
        RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        imageView.setLayoutParams(layoutParams);

        switch (configuration.getIconPosition()) {
        case LEFT_TEXT:
            textView.setCompoundDrawablesWithIntrinsicBounds(configuration.getIconResId(), 0, 0, 0);
            textView.setCompoundDrawablePadding(10);
            break;

        case RIGHT_TEXT:
            textView.setCompoundDrawablesWithIntrinsicBounds(0, 0, configuration.getIconResId(), 0);
            textView.setCompoundDrawablePadding(10);
            break;

        case LEFT:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_START);
            }

            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
            layoutParams.setMargins(25, 0, 0, 0);
            mainView.addView(imageView);

            // We redefine the layout params otherwise the image is not well aligned
            textView.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            break;
        case RIGHT:
        default:
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                layoutParams.addRule(RelativeLayout.ALIGN_PARENT_END);
            }

            layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            layoutParams.setMargins(0, 0, 25, 0);
            mainView.addView(imageView);

            // We redefine the layout params otherwise the image is not well aligned
            textView.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            break;
        }
    }
}

From source file:com.bb.hbx.activitiy.InsurancePlanActivity.java

@Override
protected void onRestart() {
    super.onRestart();
    ImageView dotView = new ImageView(mContext);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(10, 10);
    lp.leftMargin = 10;//  w  ww .j a  v  a2s.  c  o m
    dotView.setLayoutParams(lp);
    dotView.setBackgroundResource(R.drawable.dot_selected);
    dotView.setAlpha(0.38f);
    dotList.add(dotView);
    lin_add.addView(dotView);
    ComCarPropsBean.PlanListBean newBean = new ComCarPropsBean.PlanListBean();
    newBean.setSyxList(customSyxPlan);
    newBean.setJqxList(customJqxPlan);
    newBean.setFjxList(customFjxPlan);
    newBean.setQtxList(customQtxPlan);
    //planList.add(newBean);
    planList.add(prePosition, newBean);
    //?
    mCardAdapter.addViewCount();
    mCardAdapter.notifyDataSetChanged();
    vp_tb.setCurrentItem(prePosition);
}

From source file:paulscode.android.mupen64plusae.SplashActivity.java

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

    // Get app data and user preferences
    mAppData = new AppData(this);
    mGlobalPrefs = new GlobalPrefs(this, mAppData);
    mGlobalPrefs.enforceLocale(this);
    mPrefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Ensure that any missing preferences are populated with defaults (e.g. preference added to
    // new release)
    PreferenceManager.setDefaultValues(this, R.xml.preferences_audio, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_data, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_display, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_input, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_library, false);
    PreferenceManager.setDefaultValues(this, R.xml.preferences_touchscreen, false);

    // Ensure that selected plugin names and other list preferences are valid
    // @formatter:off
    final Resources res = getResources();
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_ORIENTATION, R.string.displayOrientation_default,
            R.array.displayOrientation_values);
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_POSITION, R.string.displayPosition_default,
            R.array.displayPosition_values);
    PrefUtil.validateListPreference(res, mPrefs, DISPLAY_SCALING, R.string.displayScaling_default,
            R.array.displayScaling_values);
    PrefUtil.validateListPreference(res, mPrefs, VIDEO_HARDWARE_TYPE, R.string.videoHardwareType_default,
            R.array.videoHardwareType_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_PLUGIN, R.string.audioPlugin_default,
            R.array.audioPlugin_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_SDL_BUFFER_SIZE, R.string.audioSDLBufferSize_default,
            R.array.audioSDLBufferSize_values);
    PrefUtil.validateListPreference(res, mPrefs, AUDIO_SLES_BUFFER_SIZE, R.string.audioSLESBufferSize_default,
            R.array.audioSLESBufferSize_values);
    PrefUtil.validateListPreference(res, mPrefs, TOUCHSCREEN_AUTO_HOLD, R.string.touchscreenAutoHold_default,
            R.array.touchscreenAutoHold_values);
    PrefUtil.validateListPreference(res, mPrefs, NAVIGATION_MODE, R.string.navigationMode_default,
            R.array.navigationMode_values);

    if (!mPrefs.getBoolean("seen_survey", false)) {
        LinearLayout dialogLayout = new LinearLayout(this);
        dialogLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        dialogLayout.setOrientation(LinearLayout.VERTICAL);
        TextView message = new TextView(this);
        message.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        message.setText("We have recently changed our icon and we want your feedback!\n\n"
                + "Please take a few moments to fill out this feedback form so we can make improvements. "
                + "You will need a Google account to fill out this form. This is so we don't have duplicates.");
        message.setPadding(16, 16, 16, 16);
        dialogLayout.addView(message);//from w ww .jav  a2 s  .c om
        ImageView icon = new ImageView(this);
        icon.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        icon.setAdjustViewBounds(true);
        icon.setPadding(16, 16, 16, 16);
        icon.setImageResource(R.drawable.ic_playstore_ouya);
        dialogLayout.addView(icon);
        AlertDialog dialog = new AlertDialog.Builder().setTitle("We want your feedback!").setView(iconLayout)
                .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(
                                "https://docs.google.com/forms/d/1F2stkHvb0Rx5vfmaz50OtTfT73XjHK2GEXZj9a_x-yw/viewform"));
                        SplashActivity.this.startActivity(i);
                    }
                }).setNegativeButton(getString(android.R.string.cancel), null).create();
        mPrefs.edit().putBoolean("seen_survey", true).apply();
        dialog.show();
    }
    //Check for invalid data path
    String dataPathString = mPrefs.getString(DATA_PATH, null);

    if (dataPathString == null || dataPathString.isEmpty()
            || dataPathString.contains(res.getString(R.string.pathGameSaves_default))) {
        String defValue = res.getString(R.string.pathGameSaves_default);
        String newDefValue = PathPreference.validate(defValue);

        mPrefs.edit().putString(DATA_PATH, newDefValue).commit();
    }

    // @formatter:on

    // Refresh the preference data wrapper
    mGlobalPrefs = new GlobalPrefs(this, mAppData);

    // Make sure custom skin directory exist
    new File(mGlobalPrefs.touchscreenCustomSkinsDir).mkdirs();

    // Initialize the OUYA interface if running on OUYA
    if (AppData.IS_OUYA_HARDWARE)
        OuyaFacade.getInstance().init(this, DEVELOPER_ID);

    // Initialize the toast/status bar notifier
    Notifier.initialize(this);

    // Don't let the activity sleep in the middle of extraction
    getWindow().setFlags(LayoutParams.FLAG_KEEP_SCREEN_ON, LayoutParams.FLAG_KEEP_SCREEN_ON);

    // Lay out the content
    setContentView(R.layout.splash_activity);
    mTextView = (TextView) findViewById(R.id.mainText);

    if (mGlobalPrefs.isBigScreenMode) {
        final ImageView splash = (ImageView) findViewById(R.id.mainImage);
        splash.setImageResource(R.drawable.publisherlogo_ouya);
    }

    requestPermissions();

    // Popup a warning if the installation appears to be corrupt
    if (!mAppData.isValidInstallation()) {
        Popups.showInvalidInstall(this);
    }
}

From source file:com.se.cronus.AbstractCActivity.java

protected void setUpActionBar() {
    ImageView icon = new ImageView(this);
    icon.setBackgroundResource(com.se.cronus.R.drawable.temp_cronos_logo);
    act = this.getActionBar();
    act.setBackgroundDrawable(new ColorDrawable(CUtils.CRONUS_GREEN_DARK));
    act.setIcon(com.se.cronus.R.drawable.temp_cronos_logo);
    act.setCustomView(com.se.cronus.R.layout.action_bar);
    act.setDisplayHomeAsUpEnabled(true);
    act.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME);
    ((ViewGroup) act.getCustomView().getParent()).addView(icon);
    // extra icons
    search = (ImageView) findViewById(com.se.cronus.R.id.action_search_b);
    refresh = (ImageView) findViewById(com.se.cronus.R.id.action_refresh);
    searchTextE = (EditText) findViewById(com.se.cronus.R.id.action_search_et);
    searchTextV = (TextView) findViewById(com.se.cronus.R.id.action_search_tv);
    item = (ImageView) findViewById(com.se.cronus.R.id.action_item);

    searchTextE.setTextColor(Color.WHITE);
    searchTextE.setTextSize(15);//from  w w w .j ava2  s. c om
    searchTextE.setImeOptions(EditorInfo.IME_ACTION_SEARCH);

    searchTextV.setTextColor(Color.WHITE);
    searchTextV.setTextSize(15);

    ImageView logo = (ImageView) findViewById(com.se.cronus.R.id.temp_cronos_logo);
    logo.setLayoutParams(new RelativeLayout.LayoutParams(act.getHeight(), act.getHeight()));

}

From source file:org.alfresco.mobile.android.application.fragments.user.UserSearchFragment.java

@Override
protected void prepareEmptyView(View ev, ImageView emptyImageView, TextView firstEmptyMessage,
        TextView secondEmptyMessage) {//from  ww  w  . j a v a 2  s.  com
    emptyImageView.setLayoutParams(DisplayUtils.resizeLayout(getActivity(), 275, 275));
    emptyImageView.setImageResource(R.drawable.ic_empty_search_people);
    firstEmptyMessage.setText(R.string.people_search_empty_title);
    secondEmptyMessage.setVisibility(View.VISIBLE);
    secondEmptyMessage.setText(R.string.people_search_empty_description);
}

From source file:Main.java

public static void scaleImageWithOriRatio(ImageView view, int boundBoxInDp) {
    // Get the ImageView and its bitmap
    Drawable drawing = view.getDrawable();
    Bitmap bitmap = ((BitmapDrawable) drawing).getBitmap();

    // Get current dimensions
    int width = bitmap.getWidth();
    int height = bitmap.getHeight();

    // Determine how much to scale: the dimension requiring less scaling is
    // closer to the its side. This way the image always stays inside your
    // bounding box AND either x/y axis touches it.
    float xScale = ((float) boundBoxInDp) / width;
    float yScale = ((float) boundBoxInDp) / height;
    float scale = (xScale <= yScale) ? xScale : yScale;

    // Create a matrix for the scaling and add the scaling data
    Matrix matrix = new Matrix();
    matrix.postScale(scale, scale);/*from   w ww  .j a v  a 2 s .  c om*/

    // Create a new bitmap and convert it to a format understood by the
    // ImageView
    Bitmap scaledBitmap = Bitmap.createBitmap(bitmap, 0, 0, width, height, matrix, true);
    BitmapDrawable result = new BitmapDrawable(scaledBitmap);
    width = scaledBitmap.getWidth();
    height = scaledBitmap.getHeight();

    // Apply the scaled bitmap
    view.setImageDrawable(result);

    // Now change ImageView's dimensions to match the scaled image
    LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
    params.width = width;
    params.height = height;
    view.setLayoutParams(params);
}

From source file:com.zt.hackman.model.HackmanModel.java

/**
 * ?//  w  w  w .  ja  va  2  s . c o m
 */
public void changeImage(ImageItem item, int current, RelativeLayout btn) {

    btn.removeAllViews();
    ImageView imageView = new ImageView(ac);
    imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));
    btn.addView(imageView);
    ImageLoader.getInstance().displayImage("file://" + item.path, imageView, BaseApp.options);
    switch (current) {
    case 1:
        response.idenFrontImage = new File(item.path);
        break;
    case 2:
        response.idenReserveImage = new File(item.path);
        break;
    case 3:
        response.driveImage = new File(item.path);
        break;
    case 4:
        response.driveImage2 = new File(item.path);
        break;
    case 5:
        response.doBusinessImage = new File(item.path);
        break;
    case 6:
        response.vehicleImg = new File(item.path);
        break;
    case 7:
        response.vehicleLicenseImg = new File(item.path);
        break;
    case 8:
        response.vehicleLicenseImg2 = new File(item.path);
        break;
    case 9:
        response.operationLicenseImg = new File(item.path);
        break;

    }

}

From source file:net.simno.klingar.ui.DetailController.java

private void showBackgroundImage(String imageTranscodeUri, int viewType) {
    // Add background image and layout programmatically
    ImageView background = new SquareImageView(getActivity());
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(imageWidth, imageHeight);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    background.setLayoutParams(params);

    backgroundLayout = new BackgroundLayout(getActivity(), background, backgroundHeight - toolbarHeight);
    backgroundLayout.setBackgroundColor(primaryColor);

    detailContainer.addView(backgroundLayout, 0,
            new RelativeLayout.LayoutParams(MATCH_PARENT, backgroundHeight));

    // Load background image into image view
    if (viewType == Type.ARTIST) {
        Glide.with(getActivity()).load(Urls.addTranscodeParams(imageTranscodeUri, imageWidth, imageHeight))
                .asBitmap().centerCrop().into(new CircleImageViewTarget(background));
    } else {//from  w w w  .  j a  v a2s.com
        Glide.with(getActivity()).load(Urls.addTranscodeParams(imageTranscodeUri, imageWidth, imageHeight))
                .centerCrop().into(background);
    }

    // Set recyclerview top padding to background height
    recyclerView.setPadding(recyclerView.getPaddingStart(), backgroundHeight, recyclerView.getPaddingEnd(),
            recyclerView.getPaddingBottom());

    // Add scroll listener that handles toolbar fading and background parallax effects
    BackgroundScrollListener backgroundScrollListener = new BackgroundScrollListener(ORIENTATION_PORTRAIT,
            backgroundHeight, toolbarHeight);
    backgroundScrollListener.setController(this);
    scrollListener = backgroundScrollListener;
    recyclerView.addOnScrollListener(scrollListener);
}

From source file:com.nike.plusgps.nikeplusgallery.MainActivity.java

/**
 * Handles the screen layouts based on the orientation.
 * The activity is not restarted when the orientation changes.
 *///from  w  w  w  .  j ava  2  s.c  o  m
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    // In Portrait mode the grid view is displayed
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {

        setContentView(R.layout.activity_main_port);
        GridView view = (GridView) findViewById(R.id.gridView);
        adapter = new FlickrFeedAdapter(getApplicationContext(), R.layout.single_elem_port, flickrFeedList,
                dbHelper, mMemoryCache);
        view.setAdapter(adapter);

    } else { // In Landscape mode the carousel view is displayed

        setContentView(R.layout.activity_main_land);
        carouselElement = (LinearLayout) findViewById(R.id.carousel);
        // Compute width of a carousel item based on screen width and initial item count
        final DisplayMetrics displayMetrics = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
        final int imageWidth = (int) (displayMetrics.widthPixels / INITIAL_ITEMS_COUNT);

        // Fetches image url from SQLite cache
        ImageView imageItem;
        String imgURL;
        for (int i = 0; i < flickrFeedList.size(); ++i) {
            imageItem = new ImageView(this);
            imgURL = flickrFeedList.get(i).getMedia();
            new DownloadImageTask(imageItem).execute(imgURL);
            imageItem.setLayoutParams(new LinearLayout.LayoutParams(imageWidth, imageWidth));
            carouselElement.addView(imageItem);
        }
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.feed.objects.AppObj.java

@Override
public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    PackageManager pm = context.getPackageManager();
    Drawable icon = null;/*from   w  w w. java  2s.c om*/
    String appName;
    if (obj.getJson() != null && obj.getJson().has(ANDROID_PACKAGE_NAME)) {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
    } else {
        appName = "Unknown";
    }
    if (!(obj instanceof DbObj)) {
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Preparing application " + appName + "...";
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
        return;
    }

    DbObj dbParentObj = (DbObj) obj;
    boolean rendered = false;

    Intent launch = getLaunchIntent(context, dbParentObj);
    List<ResolveInfo> infos = pm.queryIntentActivities(launch, 0);
    if (infos.size() > 0) {
        ResolveInfo info = infos.get(0);
        if (info.activityInfo.labelRes != 0) {
            appName = info.activityInfo.loadLabel(pm).toString();
            icon = info.loadIcon(pm);
        } else {
            appName = info.activityInfo.name;
        }
    } else {
        appName = obj.getJson().optString(ANDROID_PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
    }
    // TODO: Safer reference to containing view
    if (icon != null) {
        View parentView = (View) frame.getParent().getParent();
        ImageView avatar = (ImageView) parentView.findViewById(R.id.icon);
        avatar.setImageDrawable(icon);

        TextView label = (TextView) parentView.findViewById(R.id.name_text);
        label.setText(appName);
    }

    // TODO: obj.getLatestChild().render();
    String selection = getRenderableClause();
    String[] selectionArgs = null;
    Cursor cursor = dbParentObj.getSubfeed().query(selection, selectionArgs);
    if (cursor.moveToFirst()) {
        DbObj dbObj = App.instance().getMusubi().objForCursor(cursor);
        DbObjects.getFeedRenderer(dbObj.getType()).render(context, frame, dbObj, allowInteractions);
        rendered = true;
    }

    if (!rendered) {
        String text;
        if (icon != null) {
            ImageView iv = new ImageView(context);
            iv.setImageDrawable(icon);
            iv.setAdjustViewBounds(true);
            iv.setMaxWidth(60);
            iv.setMaxHeight(60);
            iv.setLayoutParams(CommonLayouts.WRAPPED);
            frame.addView(iv);
            text = appName;
        } else {
            text = "New application: " + appName + ".";
        }
        // TODO: Show Market icon or app icon.
        TextView valueTV = new TextView(context);
        valueTV.setText(text);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }
}