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.pikachu.emoji.widget.EmojiView.java

/**
 * ?</br>//  ww w .j a v  a 2s .  c  o  m
 * 
 * @return
 */
private ImageView createIndicator() {
    ImageView imageView = new ImageView(getContext());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(30, 30);
    params.gravity = Gravity.CENTER;
    imageView.setLayoutParams(params);
    imageView.setImageDrawable(ResFinder.getDrawable(mNormalIcon));
    imageView.setPadding(0, 0, 10, 0);
    return imageView;
}

From source file:com.egoclean.testpregnancy.util.ActivityHelper.java

/**
 * Adds an action bar button to the compatibility action bar (on phones).
 *///from   w w  w. ja va  2 s.com
private View addActionButtonCompat(int iconResId, int textResId, View.OnClickListener clickListener,
        boolean separatorAfter) {
    final ViewGroup actionBar = getActionBarCompat();
    if (actionBar == null) {
        return null;
    }

    // Create the separator
    ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle);
    separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT));

    // Create the button
    ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle);
    actionButton.setLayoutParams(new ViewGroup.LayoutParams(
            (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height),
            ViewGroup.LayoutParams.FILL_PARENT));
    actionButton.setImageResource(iconResId);
    actionButton.setScaleType(ImageView.ScaleType.CENTER);
    actionButton.setContentDescription(mActivity.getResources().getString(textResId));
    actionButton.setOnClickListener(clickListener);

    // Add separator and button to the action bar in the desired order

    if (!separatorAfter) {
        actionBar.addView(separator);
    }

    actionBar.addView(actionButton);

    if (separatorAfter) {
        actionBar.addView(separator);
    }

    return actionButton;
}

From source file:de.skubware.opentraining.activity.create_workout.ExerciseTypeDetailFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_exercisetype_detail, container, false);
    ViewGroup rootLayout = (ViewGroup) rootView.findViewById(R.id.fragment_exercisetype_detail_layout);

    // If Image Exists
    if (!mExercise.getImagePaths().isEmpty()) {
        // Create Image View
        ImageView imageView = new ImageView(rootView.getContext());
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        imageView.setPadding(20, 20, 20, 20);
        rootLayout.addView(imageView);/*from   w  ww . j a  v  a  2s  . co m*/
        imageView.setVisibility(View.VISIBLE);

        // set gesture detector
        this.mGestureScanner = new GestureDetector(this.getActivity(),
                new ExerciseDetailOnGestureListener(this, imageView, mExercise));

        //Set Image
        DataHelper data = new DataHelper(getActivity());
        imageView.setImageDrawable(data.getDrawable(mExercise.getImagePaths().get(0).toString()));

        rootView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return mGestureScanner.onTouchEvent(event);
            }
        });
    } else {
        TextView textView = new TextView(rootView.getContext());
        textView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        textView.setGravity(Gravity.CENTER);
        textView.setPadding(10, 10, 10, 10);
        textView.setText(Html.fromHtml(mExercise.getDescription()));
        rootLayout.addView(textView);
    }
    return rootView;
}

From source file:us.nineworlds.serenity.volley.YouTubeTrailerSearchResponseListener.java

@Override
public void onResponse(JSONObject response) {
    try {//from ww w. j  av a  2  s  .com
        JSONArray items = response.getJSONArray("items");
        View trailerIndicator = posterView.findViewById(R.id.trailerIndicator);
        View infoGraphicMeta = posterView.findViewById(R.id.infoGraphicMeta);

        JSONObject item = items.getJSONObject(0);
        JSONObject youtubeId = item.getJSONObject("id");

        String id = youtubeId.getString("videoId");

        createMetaData(id);
        if (trailerIndicator != null) {
            trailerIndicator.setVisibility(View.VISIBLE);
            infoGraphicMeta.setVisibility(View.VISIBLE);
        } else {
            Activity context = (Activity) posterView.getContext();
            LinearLayout infographicsView = (LinearLayout) context.findViewById(R.id.movieInfoGraphicLayout);
            ImageView ytImage = new ImageView(context);
            ytImage.setImageResource(R.drawable.yt_social_icon_red_128px);
            ytImage.setScaleType(ScaleType.FIT_XY);
            int w = ImageUtils.getDPI(45, context);
            int h = ImageUtils.getDPI(24, context);
            ytImage.setLayoutParams(new LinearLayout.LayoutParams(w, h));
            LinearLayout.LayoutParams p = (LinearLayout.LayoutParams) ytImage.getLayoutParams();
            p.leftMargin = 5;
            p.gravity = Gravity.CENTER_VERTICAL;
            infographicsView.addView(ytImage);
        }

        video.setTrailer(true);
        video.setTrailerId(id);
    } catch (JSONException e) {
        Log.d(getClass().getName(), e.getMessage(), e);
    }
}

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

public void render(final Context context, final ViewGroup frame, Obj obj, boolean allowInteractions) {
    JSONObject content = obj.getJson();/*from   w  w  w  .j  a v a 2 s .c  o m*/
    // TODO: hack to show object history in app feeds
    JSONObject appState = getAppState(context, content);
    if (appState != null) {
        content = appState;
    } else {
        Log.e(TAG, "Missing inner content, probably because of format changes");
    }

    boolean rendered = false;
    AppState ref = new AppState(content);
    String thumbnail = ref.getThumbnailImage();
    if (thumbnail != null) {
        rendered = true;
        ImageView imageView = new ImageView(context);
        imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        App.instance().objectImages.lazyLoadImage(thumbnail.hashCode(), thumbnail, imageView);
        frame.addView(imageView);
    }

    thumbnail = ref.getThumbnailText();
    if (thumbnail != null) {
        rendered = true;
        TextView valueTV = new TextView(context);
        valueTV.setText(thumbnail);
        valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        valueTV.setGravity(Gravity.TOP | Gravity.LEFT);
        frame.addView(valueTV);
    }

    thumbnail = ref.getThumbnailHtml();
    if (thumbnail != null) {
        rendered = true;
        WebView webview = new WebView(context);
        webview.loadData(thumbnail, "text/html", "UTF-8");
        webview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        Object o = frame.getTag(R.id.object_entry);
        webview.setOnTouchListener(new WebViewClickListener(frame, (Integer) o));
        frame.addView(webview);
    }

    if (!rendered) {
        String appName = content.optString(PACKAGE_NAME);
        if (appName.contains(".")) {
            appName = appName.substring(appName.lastIndexOf(".") + 1);
        }
        String text = "Welcome to " + appName + "!";
        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);
    }
}

From source file:com.egoclean.testpregnancy.util.ActivityHelper.java

/**
 * Adds an action button to the compatibility action bar, using menu information from a
 * {@link android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state
 * can be changed to show a loading spinner using
 * {@link ActivityHelper#setRefreshActionButtonCompatState(boolean)}.
 *///from w  ww  .ja v  a  2  s  .c  o  m
private View addActionButtonCompatFromMenuItem(final MenuItem item) {
    final ViewGroup actionBar = getActionBarCompat();
    if (actionBar == null) {
        return null;
    }

    // Create the separator
    ImageView separator = new ImageView(mActivity, null, R.attr.actionbarCompatSeparatorStyle);
    separator.setLayoutParams(new ViewGroup.LayoutParams(2, ViewGroup.LayoutParams.FILL_PARENT));

    // Create the button
    ImageButton actionButton = new ImageButton(mActivity, null, R.attr.actionbarCompatButtonStyle);
    actionButton.setId(item.getItemId());
    actionButton.setLayoutParams(new ViewGroup.LayoutParams(
            (int) mActivity.getResources().getDimension(R.dimen.actionbar_compat_height),
            ViewGroup.LayoutParams.FILL_PARENT));
    actionButton.setImageDrawable(item.getIcon());
    actionButton.setScaleType(ImageView.ScaleType.CENTER);
    actionButton.setContentDescription(item.getTitle());
    actionButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
        }
    });

    actionBar.addView(separator);
    actionBar.addView(actionButton);

    if (item.getItemId() == R.id.menu_refresh) {
        // Refresh buttons should be stateful, and allow for indeterminate progress indicators,
        // so add those.
        int buttonWidth = mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height);
        int buttonWidthDiv3 = buttonWidth / 3;
        ProgressBar indicator = new ProgressBar(mActivity, null, R.attr.actionbarCompatProgressIndicatorStyle);
        LinearLayout.LayoutParams indicatorLayoutParams = new LinearLayout.LayoutParams(buttonWidthDiv3,
                buttonWidthDiv3);
        indicatorLayoutParams.setMargins(buttonWidthDiv3, buttonWidthDiv3, buttonWidth - 2 * buttonWidthDiv3,
                0);
        indicator.setLayoutParams(indicatorLayoutParams);
        indicator.setVisibility(View.GONE);
        indicator.setId(R.id.menu_refresh_progress);
        actionBar.addView(indicator);
    }

    return actionButton;
}

From source file:mobisocial.musubi.objects.FileObj.java

@Override
public View createView(Context context, ViewGroup frame) {
    LinearLayout container = new LinearLayout(context);
    container.setLayoutParams(CommonLayouts.FULL_WIDTH);
    container.setOrientation(LinearLayout.HORIZONTAL);
    container.setGravity(Gravity.CENTER);

    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    TextView valueTV = new TextView(context);

    valueTV.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));
    valueTV.setGravity(Gravity.BOTTOM | Gravity.LEFT);
    valueTV.setPadding(4, 0, 0, 0);/*  ww  w  .  j av  a  2  s .  c  o m*/

    container.addView(imageView);
    container.addView(valueTV);
    return container;
}

From source file:ca.zadrox.dota2esportticker.ui.TeamSearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.team_search, menu);
    MenuItem searchItem = menu.findItem(R.id.action_search);
    Toolbar.LayoutParams params = new Toolbar.LayoutParams(Toolbar.LayoutParams.MATCH_PARENT,
            Toolbar.LayoutParams.MATCH_PARENT);

    SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
    mSearchView = (SearchView) searchItem.getActionView();
    mSearchView.setSearchableInfo(searchManager.getSearchableInfo(getComponentName()));

    mSearchView.setLayoutParams(params);
    mSearchView.setMaxWidth(getResources().getDisplayMetrics().widthPixels);

    mSearchView.setIconifiedByDefault(false);
    mSearchView.setQueryHint("Search");

    ImageView magImage = (ImageView) mSearchView.findViewById(R.id.search_mag_icon);
    magImage.setLayoutParams(new LinearLayout.LayoutParams(0, 0));

    final EditText editText = (AutoCompleteTextView) mSearchView.findViewById(R.id.search_src_text);
    editText.setHintTextColor(getResources().getColor(R.color.theme_primary_light));

    if (mQuery != null) {
        mSearchView.setQuery(mQuery, false);
    } else {/*  w ww  .  j ava2s. c  o m*/
        mSearchView.requestFocus();
    }

    mSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() {
        @Override
        public boolean onSuggestionSelect(int i) {
            return onSuggestionClick(i);
        }

        @Override
        public boolean onSuggestionClick(int i) {
            Cursor c = (Cursor) mSearchView.getSuggestionsAdapter().getItem(i);
            mSearchView.setQuery(c.getString(1), true);
            mSearchView.clearFocus();

            return true;
        }
    });

    return true;
}

From source file:com.esri.arcgisruntime.sample.editfeatureattachments.MainActivity.java

/**
 * Create a Layout for callout/*ww  w  . j av  a2  s.  c om*/
 */
private void createCallout() {

    // create content text view for the callout
    mCalloutLayout = new RelativeLayout(getApplicationContext());
    TextView calloutContent = new TextView(getApplicationContext());
    calloutContent.setId(R.id.calloutTextView);
    calloutContent.setTextColor(Color.BLACK);
    calloutContent.setTextSize(18);

    RelativeLayout.LayoutParams relativeParamsBelow = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relativeParamsBelow.addRule(RelativeLayout.BELOW, calloutContent.getId());

    // create attachment text view for the callout
    TextView calloutAttachment = new TextView(getApplicationContext());
    calloutAttachment.setId(R.id.attchTV);
    calloutAttachment.setTextColor(Color.BLACK);
    calloutAttachment.setTextSize(13);
    calloutContent.setPadding(0, 20, 20, 0);
    calloutAttachment.setLayoutParams(relativeParamsBelow);

    RelativeLayout.LayoutParams relativeParamsRightOf = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    relativeParamsRightOf.addRule(RelativeLayout.RIGHT_OF, calloutAttachment.getId());

    // create image view for the callout
    ImageView imageView = new ImageView(getApplicationContext());
    imageView.setImageDrawable(ContextCompat.getDrawable(getApplicationContext(), R.drawable.ic_info));
    imageView.setLayoutParams(relativeParamsRightOf);
    imageView.setOnClickListener(new ImageViewOnclickListener());

    mCalloutLayout.addView(calloutContent);
    mCalloutLayout.addView(imageView);
    mCalloutLayout.addView(calloutAttachment);

}

From source file:com.oasis.sdk.activity.OasisSdkPayEpinActivity.java

private void initImage(List<String> imgUrls) {
    if (imgUrls == null || imgUrls.size() <= 0)
        return;//from   ww  w  .  j a  v a2 s. c  o  m

    int size = imgUrls.size();
    if (size > 4)// 4
        size = 4;
    Rect r = new Rect();
    et_code.getGlobalVisibleRect(r);

    int width = r.right - r.left;
    int singWidth = width / size;

    int imgWidth = DisplayUtil.dip2px(70, BaseUtils.getDensity());
    int imgHeight = DisplayUtil.dip2px(30, BaseUtils.getDensity());

    double l = singWidth / (double) imgWidth;
    if (l <= 1) {
        imgWidth = singWidth;
    } else {
        l = Math.round(l * 100) * 0.01d;// ?2??

        imgWidth *= l;
        imgHeight *= l;
    }

    for (int i = 0; i < size; i++) {
        // ? 105*45
        final ImageView img = new ImageView(this.getApplicationContext());
        img.setLayoutParams(new LayoutParams(imgWidth, imgHeight));
        img.setImageResource(BaseUtils.getResourceValue("drawable", "oasisgames_sdk_payway_mob_epin"));
        ImageRequest iq = new ImageRequest(imgUrls.get(i), new Response.Listener<Bitmap>() {

            @Override
            public void onResponse(final Bitmap arg0) {
                if (arg0 == null)
                    return;
                img.setImageBitmap(arg0);
                img.postInvalidate();
            }
        }, imgWidth, // ???
                imgHeight, Config.ARGB_8888, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError arg0) {

                        setWaitScreen(false);
                    }

                });
        iq.setRetryPolicy(new DefaultRetryPolicy(60000, 2, 1));
        ApplicationContextManager.getInstance().getVolleyRequestQueue().add(iq);

        ll_images.addView(img);
    }
    if (ll_images.getChildCount() > 0) {
        ll_images.setVisibility(View.VISIBLE);
    }
}