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.sft.blackcatapp.EnrollSchoolActivity.java

private void setViewPager() {
    InfinitePagerAdapter adapter = null;
    int length = 0;
    if (adImageUrl != null && adImageUrl.length > 0) {
        adapter = new InfinitePagerAdapter(this, adImageUrl, screenWidth, viewPagerHeight);
        length = adImageUrl.length;/*from  w ww.  ja  v a 2s.co m*/
    } else {
        adapter = new InfinitePagerAdapter(this, new int[] { R.drawable.defaultimage });
        length = 1;
        defaultImage.setVisibility(View.GONE);
    }
    adapter.setPageClickListener(new MyPageClickListener());
    adapter.setURLErrorListener(this);
    topViewPager.setAdapter(adapter);

    imageViews = new ImageView[length];
    ImageView imageView = null;
    dotLayout.removeAllViews();
    LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams((int) (8 * screenDensity),
            (int) (4 * screenDensity));
    dotLayout.addView(new TextView(this), textParams);
    // ?
    for (int i = 0; i < length; i++) {
        imageView = new ImageView(this);
        // ?imageview?
        imageView.setLayoutParams(new LayoutParams((int) (6 * screenDensity), (int) (6 * screenDensity)));// ?20
        // 
        // ?layout
        imageView.setBackgroundResource(R.drawable.enroll_school_dot_selector);
        imageViews[i] = imageView;

        // ???
        if (i == 0) {
            imageView.setEnabled(true);
        } else {
            imageView.setEnabled(false);
        }
        // imageviews?
        dotLayout.addView(imageViews[i]);
        dotLayout.addView(new TextView(this), textParams);
    }
}

From source file:dev.journey.uitoolkit.view.FlexibleTabLayout.java

private ImageView getDefaultImageView() {
    ImageView imageView = new ImageView(getContext());
    float density = getResources().getDisplayMetrics().density;
    LayoutParams layoutParams = new LayoutParams((int) (24 * density), (int) (24 * density));
    imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    imageView.setLayoutParams(layoutParams);
    return imageView;
}

From source file:com.roger.lineselectionwebview.LSWebView.java

/**
 * ?/*  w w w . j  a  va2  s .co  m*/
 */
private void drawImage() {
    int size = rectList.size();
    Rect endRect = rectList.get(size - 1);
    Rect realEndRect = endRect;

    // ?left???,,?
    if (size > 2) {
        Rect endPreRect = rectList.get(size - 2);
        if (endRect.left == endPreRect.left) {
            if (endRect.width() > endPreRect.width()) {
                realEndRect = endPreRect;
            } else {
                realEndRect = endRect;
            }
        }
    }

    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.del);
    ImageView imageView = new ImageView(mContext);
    imageView.setImageBitmap(bitmap);
    imageView.setScaleType(ScaleType.CENTER);
    imageView.setTag(selectContext);
    MyAbsoluteLayout.LayoutParams lp = new MyAbsoluteLayout.LayoutParams(
            MyAbsoluteLayout.LayoutParams.WRAP_CONTENT, MyAbsoluteLayout.LayoutParams.WRAP_CONTENT,
            realEndRect.right, realEndRect.bottom);
    imageView.setLayoutParams(lp);

    imageView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            String tag = (String) v.getTag();
            lineView.remove(tag);
            myLayout.removeView(v);
            if (onTextSelectListener != null) {
                onTextSelectListener.cancle(tag.split(SELECT_SPLIT)[0]);
            }
        }

    });
    myLayout.addView(imageView, lp);
}

From source file:com.ndn.menurandom.ImageDownloader.java

private void makeFrameLayout(ImageView imageView) {
    boolean isExist = false;
    ViewGroup vg = (ViewGroup) imageView.getParent();
    if (vg instanceof FrameLayout) {
        FrameLayout frameLayout = (FrameLayout) vg;
        String tag = (String) frameLayout.getTag();
        if (tag != null && tag.equals("fl_imagedownloader")) {
            isExist = true;//from w w  w  .  j  ava2s.  com
        }
    }

    if (!isExist) {
        int childCount = vg.getChildCount();
        int index = 0;
        while (index < childCount) {
            if (imageView == vg.getChildAt(index)) {
                break;
            }
            index++;
        }
        vg.removeViewAt(index);

        FrameLayout frameLayout = new FrameLayout(vg.getContext().getApplicationContext());
        frameLayout.setTag("fl_imagedownloader");
        ViewGroup.LayoutParams lpImageView = (ViewGroup.LayoutParams) imageView.getLayoutParams();
        frameLayout.setLayoutParams(lpImageView);
        imageView.setLayoutParams(new LayoutParams(lpImageView.width, lpImageView.height));
        frameLayout.setPadding(imageView.getPaddingLeft(), imageView.getPaddingTop(),
                imageView.getPaddingRight(), imageView.getPaddingBottom());
        imageView.setPadding(0, 0, 0, 0);
        frameLayout.addView(imageView);
        vg.addView(frameLayout, index);

        ProgressBar progressBar = new ProgressBar(frameLayout.getContext());
        progressBar.setTag("pb_imagedownloader");
        int leftRightPadding = (imageView.getLayoutParams().width - 50) / 2;
        int topBottomPadding = (imageView.getLayoutParams().height - 50) / 2;
        progressBar.setPadding(leftRightPadding, topBottomPadding, leftRightPadding, topBottomPadding);
        frameLayout.addView(progressBar);

    }
}

From source file:com.google.samples.apps.iosched.session.SessionDetailFragment.java

/**
 * Aligns the Twitter icon the parent bottom right. Aligns the G+ icon to the left of the
 * Twitter icon if it is present. Otherwise, aligns the G+ icon to the parent bottom right.
 *///  w  ww .j  ava  2  s  .c  o m
private void determineSocialIconPlacement(ImageView plusOneIcon, ImageView twitterIcon) {
    if (plusOneIcon.getVisibility() == View.VISIBLE) {
        // Set the dimensions of the G+ button.
        int socialIconDimension = getResources().getDimensionPixelSize(R.dimen.social_icon_box_size);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(socialIconDimension,
                socialIconDimension);
        params.addRule(RelativeLayout.BELOW, R.id.speaker_abstract);
        params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);

        if (twitterIcon.getVisibility() == View.VISIBLE) {
            params.addRule(RelativeLayout.LEFT_OF, R.id.twitter_icon_box);
        } else {
            params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        }
        plusOneIcon.setLayoutParams(params);
    }
}

From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java

private View getEmptyHomeView(LayoutInflater inflater) {
    final View emptyHomeView = inflater.inflate(R.layout.empty_home_view, null);
    // Set image margins.
    final ImageView image = (ImageView) emptyHomeView.findViewById(R.id.empty_home_image);
    final LayoutParams params = (LayoutParams) image.getLayoutParams();
    final int screenHeight = getResources().getDisplayMetrics().heightPixels;
    final int marginTop = screenHeight / 2
            - getResources().getDimensionPixelSize(R.dimen.empty_home_view_image_offset);
    params.setMargins(0, marginTop, 0, 0);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    image.setLayoutParams(params);

    // Set up add contact button.
    final Button addContactButton = (Button) emptyHomeView.findViewById(R.id.add_contact_button);
    addContactButton.setOnClickListener(mAddContactListener);
    return emptyHomeView;
}

From source file:com.example.view.astuetz.PagerSlidingTabStrip.java

@SuppressLint("NewApi")
private void addIconTab(int position, int resId, String notification) {
    FrameLayout tabItemCon = new FrameLayout(getContext());
    ImageView tab = new ImageView(getContext());
    tab.setImageResource(resId);/*from   w w  w  .  j  a  v  a 2  s.c  om*/
    tabItemCon.addView(tab);
    tabIconlist.put(position, tab);
    ImageView notiSymbol = new ImageView(getContext());
    notiSymbol.setImageResource(R.drawable.badge_background);
    BadgeView noti = new BadgeView(getContext());
    noti.setText(notification);
    tabItemCon.addView(noti);
    tabItemCon.addView(notiSymbol);
    if (notification != null && !notification.equals("")) {
        noti.setVisibility(View.VISIBLE);
        notiSymbol.setVisibility(View.GONE);
    } else if (notification != null && notification.equals("")) {
        noti.setVisibility(View.GONE);
        notiSymbol.setVisibility(View.VISIBLE);
    } else {
        notiSymbol.setVisibility(View.GONE);
        noti.setVisibility(View.GONE);
    }
    int notiSySize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20,
            getResources().getDisplayMetrics());
    noti.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
            Gravity.RIGHT | Gravity.TOP));
    notiSymbol.setLayoutParams(new LayoutParams(notiSySize, notiSySize, Gravity.RIGHT | Gravity.TOP));
    FrameLayout tabItem = new FrameLayout(getContext());
    tabItem.addView(tabItemCon);
    tabItemCon.setLayoutParams(
            new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER));
    addTab(position, tabItem);
}

From source file:no.ntnu.idi.socialhitchhiking.map.MapActivityCreateOrEditRoute.java

/** initAddDestButton()
 * adds the Driving Through button/*from  w ww .j  a va2 s.c  om*/
 */
protected void initAddDestButton() {

    //Adds/enables the FrameLayout
    AddDestFrameLayout = new FrameLayout(this);
    AddDestFrameLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT, 80));
    AddDestFrameLayout.setEnabled(true);

    //Fills the Image Icon
    ImageView destAddIcon = new ImageView(this);
    FrameLayout.LayoutParams lliDestIcon = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lliDestIcon.setMargins(dipToPx(10), 0, 0, dipToPx(2));
    destAddIcon.setLayoutParams(lliDestIcon);
    destAddIcon.setPadding(0, dipToPx(5), 0, 0);
    destAddIcon.setImageResource(R.drawable.google_marker_thumb_mini_through);

    //Adds the imageicon to the framelayout/enables it 
    AddDestFrameLayout.addView(destAddIcon);

    //Fills/sets the text
    TextView destAddText = new TextView(this);
    FrameLayout.LayoutParams lliDest = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);
    lliDest.setMargins(0, dipToPx(5), 0, 0);
    destAddText.setLayoutParams(lliDest);
    destAddText.setPadding(dipToPx(40), dipToPx(6), 0, 0);
    destAddText.setTextSize(15);
    destAddText.setText(R.string.mapViewAcField);

    //Adds the text to the framelayout
    AddDestFrameLayout.addView(destAddText);

    //Adds the framelayout to the linearlayout (in the scrollview)
    sclLayout = (LinearLayout) findViewById(R.id.sclLayout);
    sclLayout.addView(AddDestFrameLayout, sclLayout.getChildCount());

    final Button button = ((Button) findViewById(R.id.btnChooseRoute));

    //Adds a clicklistener to the frameLayout
    AddDestFrameLayout.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            //Adds a new destination field
            initDestFrameLayout();

            //Moves the button to the bottom
            setLayoutParams();

            if (checkFields() == false) {
                button.setEnabled(false);
                button.setText("Show on map");
            } else {
                mapView.getOverlays().clear();
                createMap();
            }
        }

    });
}

From source file:com.keylesspalace.tusky.activity.ComposeActivity.java

private void addMediaToQueue(QueuedMedia.Type type, Bitmap preview, Uri uri, long mediaSize) {
    final QueuedMedia item = new QueuedMedia(type, uri, new ImageView(this), mediaSize);
    ImageView view = item.preview;
    Resources resources = getResources();
    int side = resources.getDimensionPixelSize(R.dimen.compose_media_preview_side);
    int margin = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin);
    int marginBottom = resources.getDimensionPixelSize(R.dimen.compose_media_preview_margin_bottom);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(side, side);
    layoutParams.setMargins(margin, 0, margin, marginBottom);
    view.setLayoutParams(layoutParams);
    view.setScaleType(ImageView.ScaleType.CENTER_CROP);
    view.setImageBitmap(preview);/*  ww w . ja v  a2s.  c  om*/

    view.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            removeMediaFromQueue(item);
        }
    });
    mediaPreviewBar.addView(view);
    mediaQueued.add(item);
    int queuedCount = mediaQueued.size();
    if (queuedCount == 1) {
        /* The media preview bar is actually not inset in the EditText, it just overlays it and
         * is aligned to the bottom. But, so that text doesn't get hidden under it, extra
         * padding is added at the bottom of the EditText. */
        int totalHeight = side + margin + marginBottom;
        textEditor.setPadding(textEditor.getPaddingLeft(), textEditor.getPaddingTop(),
                textEditor.getPaddingRight(), totalHeight);
        // If there's one video in the queue it is full, so disable the button to queue more.
        if (item.type == QueuedMedia.Type.VIDEO) {
            disableMediaPicking();
        }
    } else if (queuedCount >= Status.MAX_MEDIA_ATTACHMENTS) {
        // Limit the total media attachments, also.
        disableMediaPicking();
    }
    if (queuedCount >= 1) {
        showMarkSensitive(true);
    }
    waitForMediaLatch.countUp();
    if (mediaSize > STATUS_MEDIA_SIZE_LIMIT && type == QueuedMedia.Type.IMAGE) {
        downsizeMedia(item);
    } else {
        uploadMedia(item);
    }
}

From source file:org.thoughtcrime.securesms.ProfileFragment.java

private void scaleImage(ImageView view, Bitmap bitmap) {
    Bitmap scaledBitmap = scaleCenterCrop(bitmap, dpToPx(350),
            getActivity().getWindowManager().getDefaultDisplay().getWidth());

    int width = scaledBitmap.getWidth();
    int height = scaledBitmap.getHeight();

    view.setImageDrawable(new BitmapDrawable(scaledBitmap));

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) view.getLayoutParams();
    params.width = width;//ww  w  .  j  ava  2  s  .co m
    params.height = height;

    view.setLayoutParams(params);
}