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.raspi.chatapp.ui.chatting.SendImageFragment.java

/**
 * this function will initialize the ui showing the current image and reload
 * everything to make sure it is shown correctly
 *//*w  w  w.  j a va2 s.  c  o m*/
private void initUI() {
    // set the actionBar title and subtitle
    if (actionBar != null) {
        actionBar.setTitle(R.string.send_image);
        actionBar.setSubtitle(name);
        //      actionBar.setBackgroundDrawable(new ColorDrawable(getResources().getColor
        //              (R.color.action_bar_transparent)));
        //      // set the statusBar color
        //      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
        //        getActivity().getWindow().setStatusBarColor(getResources().getColor(R
        //                .color.action_bar_transparent));
    }

    // instantiate the ViewPager
    viewPager = (ViewPager) getActivity().findViewById(R.id.send_image_view_pager);
    viewPager.setAdapter(new MyPagerAdapter());
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            changePage(position, false, false);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });

    //Cancel button pressed
    getView().findViewById(R.id.send_image_cancel).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // just return to the chatFragment
            mListener.onReturnClick();
        }
    });
    //Send button pressed
    getView().findViewById(R.id.send_image_send).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // create the progressDialog that is to be shown while saving
            // the image
            ProgressDialog progressDialog = new ProgressDialog(getContext());
            if (images.size() > 1)
                progressDialog.setTitle(
                        String.format(getResources().getString(R.string.sending_images), images.size()));
            else
                progressDialog.setTitle(R.string.sending_image);
            // run the sendImage in a new thread because I am saving the
            // image and this should be done in a new thread
            new Thread(new SendImagesRunnable(new Handler(), getContext(), progressDialog)).start();
        }
    });

    // generate the overview only if there are at least 2 images
    if (images.size() > 1) {
        // the layoutParams for the imageView which has the following attributes:
        // width = height = 65dp
        // margin = 5dp
        getActivity().findViewById(R.id.send_image_overview).setVisibility(View.VISIBLE);
        int a = Constants.dipToPixel(getContext(), 65);
        RelativeLayout.LayoutParams imageViewParams = new RelativeLayout.LayoutParams(a, a);
        int b = Constants.dipToPixel(getContext(), 5);
        imageViewParams.setMargins(b, b, b, b);
        // the layoutParams for the backgroundView which has the following
        // attributes:
        // width = height = 71dp
        // margin = 2dp
        int c = Constants.dipToPixel(getContext(), 71);
        RelativeLayout.LayoutParams backgroundParams = new RelativeLayout.LayoutParams(c, c);
        int d = Constants.dipToPixel(getContext(), 2);
        backgroundParams.setMargins(d, d, d, d);
        // the layoutParams for the relativeLayout containing the image and
        // the background which has the following attributes:
        // width = height = wrap_content
        LinearLayout.LayoutParams relativeLayoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        LinearLayout linearLayout = (LinearLayout) getActivity().findViewById(R.id.send_image_overview_content);
        linearLayout.removeAllViewsInLayout();
        int i = 0;
        for (Message msg : images) {
            // set up the imageView
            ImageView imageView = new ImageView(getContext());
            imageView.setLayoutParams(imageViewParams);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            // load the bitmap async
            AsyncDrawable.BitmapWorkerTask bitmapWorker = new AsyncDrawable.BitmapWorkerTask(imageView, a, a,
                    true);
            imageView.setImageDrawable(new AsyncDrawable(getResources(), null, bitmapWorker));
            imageView.setOnClickListener(new overviewSelectListener(i++));
            bitmapWorker.execute(FileUtils.getFile(getContext(), msg.getImageUri()));
            // set up the background
            View background = new View(getContext());
            background.setLayoutParams(backgroundParams);
            background.setBackgroundColor(getActivity().getResources().getColor(R.color.colorPrimaryDark));
            // make it invisible in the beginning
            background.setVisibility(View.GONE);

            // create the relativeLayout containing them
            RelativeLayout relativeLayout = new RelativeLayout(getContext());
            relativeLayout.setLayoutParams(relativeLayoutParams);
            relativeLayout.addView(background);
            relativeLayout.addView(imageView);
            // combination of Message and overviewViews
            msg.setLayout(relativeLayout);
            msg.setBackground(background);
            linearLayout.addView(relativeLayout);
        }
    } else
        getActivity().findViewById(R.id.send_image_overview).setVisibility(View.GONE);
    changePage(current, true, true);
    showSystemUI();
}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

private void addWarningTab(final int position, String title, int resId) {
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.HORIZONTAL);
    tabLayout.setGravity(Gravity.CENTER);

    ImageView tabImg = new ImageView(getContext());
    int width = DimenUtils.dp2px(getContext(), 18);
    LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(width, width);
    tabImgParams.setMargins(0, 0, DimenUtils.dp2px(getContext(), 10), 0);
    tabImgParams.gravity = Gravity.CENTER;
    tabImg.setLayoutParams(tabImgParams);
    if (resId != -1) {
        tabImg.setBackgroundResource(resId);
        tabImg.setVisibility(View.VISIBLE);
    } else {//from w ww  . j a  v a  2  s  . co m
        tabImg.setVisibility(View.GONE);
    }
    tabLayout.addView(tabImg, 0);

    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(
            mTextChangeable ? R.color.pst_tab_changeable_text_selector : R.color.pst_tab_text_selector));
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
    tabLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mOnPageClickedLisener) {
                mOnPageClickedLisener.onPageClicked(position);
            }
            pager.setCurrentItem(position);
        }
    });
    tabLayout.addView(tab, 1);

    tabsContainer.addView(tabLayout);
}

From source file:com.phicdy.mycuration.ui.TopActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_top);

    curationFragment = new CurationListFragment();
    // Create the adapter that will return a fragment for each of the three
    // primary sections of the activity.
    mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

    // Set up the ViewPager with the sections adapter.
    mViewPager = (ViewPager) findViewById(R.id.pager);
    mViewPager.setAdapter(mSectionsPagerAdapter);
    mViewPager.addOnPageChangeListener(new PageChangeListener());
    track = (ViewGroup) findViewById(R.id.track);
    trackScroller = (HorizontalScrollView) findViewById(R.id.track_scroller);
    indicator = (View) findViewById(R.id.indicator);

    WindowManager wm = getWindowManager();
    Display disp = wm.getDefaultDisplay();
    Point size = new Point();
    disp.getSize(size);//from  www .ja  va2 s . com
    int displayWidth = size.x;
    LayoutInflater inflater = LayoutInflater.from(this);
    for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) {
        final int position = i;
        ImageView ivTab = (ImageView) inflater.inflate(R.layout.tab_item, track, false);
        ivTab.setImageResource(mSectionsPagerAdapter.getImageResource(position));
        ivTab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mViewPager.setCurrentItem(position);
            }
        });
        final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) ivTab.getLayoutParams();
        layoutParams.width = displayWidth / mSectionsPagerAdapter.getCount();
        ivTab.setLayoutParams(layoutParams);
        track.addView(ivTab);
    }

    final float density = getResources().getDisplayMetrics().density;
    indicatorOffset = (int) (INDICATOR_OFFSET_DP * density);

    setTitle(getString(R.string.home));

    dbAdapter = DatabaseAdapter.getInstance(getApplicationContext());
    setAlarmManager();
}

From source file:com.retroteam.studio.retrostudio.EditorLandscape.java

/**
 * Create all the views associated with a track.
 * @param waveDrawableID//from ww w .ja v a  2s .  c  om
 * @param projectLoad
 * @return
 */

private ImageView addTrack(int waveDrawableID, boolean projectLoad) {
    //add the track with the measure adder to the view
    //get layout
    LinearLayout track_layout = (LinearLayout) findViewById(R.id.track_layout);

    //create track container
    HorizontalScrollView track_container = new HorizontalScrollView(getApplicationContext());
    track_container.setLayoutParams(new HorizontalScrollView.LayoutParams(
            HorizontalScrollView.LayoutParams.MATCH_PARENT, displaysize.y / 4));
    track_container.setBackground(getResources().getDrawable(R.color.track_container_bg));

    //create grid layout
    GridLayout track_grid = new GridLayout(getApplicationContext());
    track_grid.setColumnCount(100);
    track_grid.setRowCount(1);
    track_grid.setOrientation(GridLayout.HORIZONTAL);
    track_grid.setId(R.id.track_grid);

    //create linear layout for track id and wave
    LinearLayout track_identifier = new LinearLayout(getApplicationContext());
    track_identifier.setLayoutParams(new LinearLayout.LayoutParams(displaysize.x / 14, displaysize.y / 4));
    track_identifier.setOrientation(LinearLayout.VERTICAL);
    track_identifier.setBackgroundColor(getResources().getColor(R.color.black_overlay));

    //create textview for linear layout
    TextView track_num = new TextView(getApplicationContext());
    track_num.setText("1");
    track_num.setTextSize(45);
    track_num.setGravity(Gravity.CENTER | Gravity.CENTER_VERTICAL);

    //create imageview for linear layout
    ImageView track_type = new ImageView(getApplicationContext());
    track_type.setImageResource(waveDrawableID);
    track_type.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.MATCH_PARENT));

    //create "add measure" for grid layout
    ImageView add_measure = new ImageView(getApplicationContext());
    add_measure.setImageResource(R.drawable.measure_new);
    add_measure.setLayoutParams(new LinearLayout.LayoutParams((int) (displaysize.x / 3.32),
            LinearLayout.LayoutParams.MATCH_PARENT));
    if (projectLoad) {
        add_measure.setTag(R.id.TAG_ROW, trackReloadCounter);
        add_measure.setId(trackReloadCounter + 4200);
    } else {
        add_measure.setTag(R.id.TAG_ROW, theproject.size() - 1);
        add_measure.setId(theproject.size() - 1 + 4200);
    }

    add_measure.setTag(R.id.TAG_COLUMN, 0);
    add_measure.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            addMeasure(v, false);

        }
    });

    track_identifier.addView(track_num);
    if (projectLoad) {
        track_num.setText(Integer.toString(trackReloadCounter + 1));
        trackReloadCounter += 1;
    } else {
        track_num.setText(Integer.toString(theproject.size()));
    }
    track_num.setTextSize(45);
    track_identifier.addView(track_type);

    track_grid.addView(track_identifier);
    track_grid.addView(add_measure);

    track_container.addView(track_grid);

    track_layout.addView(track_container);

    return add_measure;

}

From source file:net.coding.program.third.MyPagerSlidingTabStrip.java

private void addIconTab(final int position, String url) {

    //      ImageButton tab = new ImageButton(getContext());
    ////from   www  . j  av  a 2s .c  o m
    //      tab.setImageResource(resId);
    //
    //      addTab(position, tab);
    View v = mInflater.inflate(net.coding.program.R.layout.imageview_head, tabsContainer, false);
    ImageView head = (ImageView) v.findViewById(net.coding.program.R.id.head);
    if (url.isEmpty()) {
        head.setImageResource(net.coding.program.R.drawable.icon_all_task);
        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) head.getLayoutParams();
        lp.leftMargin += myFirstExtraPdddingLeft;
        head.setLayoutParams(lp);
    } else {
        ImageLoader.getInstance().displayImage(Global.makeSmallUrl(head, url), head, ImageLoadTool.options);
    }

    addTab(position, v);
}

From source file:com.dycode.jepretstory.mediachooser.activity.BucketHomeFragmentActivity.java

private void onMediaSelected(MediaModel media) {

    View rootView = LayoutInflater.from(BucketHomeFragmentActivity.this)
            .inflate(R.layout.list_item_selected_thumbnail, null);
    ImageView thumbnail = (ImageView) rootView.findViewById(R.id.selected_photo);
    rootView.setTag(media.url);//from  w ww  . j  a va2  s  .  com
    rootView.setOnClickListener(this);

    int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60,
            getResources().getDisplayMetrics());
    thumbnail.setLayoutParams(new FrameLayout.LayoutParams(px, px));

    if (media.mediaMode == MediaType.VIDEO) {
        new VideoLoadAsync(getVideoFragment(), thumbnail, false, px, px)
                .executeOnExecutor(MediaAsync.THREAD_POOL_EXECUTOR, media.url);

    } else {
        ImageLoadAsync loadAsync = new ImageLoadAsync(this, thumbnail, px);
        loadAsync.executeOnExecutor(MediaAsync.THREAD_POOL_EXECUTOR, media.url);
    }

    mSelectedImagesContainer.addView(rootView, 0);

    if (mSelectedImagesContainer.getChildCount() > 0) {
        mSelectedImagesContainer.setVisibility(View.VISIBLE);
        mSelectedImageEmptyMessage.setVisibility(View.GONE);
    }
}

From source file:com.scigames.slidegame.Registration2RFIDActivity.java

public void onActivityResult(int requestCode, Intent data) {
    //public void onActivityResult(int requestCode, int resultCode, Intent data) {     
    super.onActivityResult(requestCode, 1, data);
    Log.d(TAG, "...super.onActivityResult");
    switch (requestCode) {

    case (0): {/*from  www .  j  a  v a2s . com*/
        Log.d(TAG, "...case(0)");
        //if (resultCode == Activity.RESULT_OK) { 
        //  Log.d(TAG,"...RESULT_OK");

        ImageView previewThumbnail = new ImageView(this);
        Log.d(TAG, "...newImageView");

        Bitmap b = BitmapFactory.decodeByteArray(getIntent().getByteArrayExtra("byteArray"), 0,
                getIntent().getByteArrayExtra("byteArray").length);
        Log.d(TAG, "...BitmapFactory.decodeByteArray");

        previewThumbnail.setImageBitmap(b);
        Log.d(TAG, "...setImageBitmap");

        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(30, 30);
        Log.d(TAG, "...new layoutparams");

        previewThumbnail.setLayoutParams(layoutParams);
        Log.d(TAG, "...setLayoutParams");
        //}
        break;
    }
    }
}

From source file:com.wanpaijie.www.http.ImageDownloader.java

/**
 * Download the specified image from the Internet and binds it to the provided ImageView. The
 * binding is immediate if the image is found in the cache and will be done asynchronously
 * otherwise. A null bitmap will be associated to the ImageView if an error occurs.
 *
 * @param url The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *///from w  w w. ja  va2s.  c  om
public void download(String url, ImageView imageView, Context context) {
    resetPurgeTimer();
    if (url.length() > 0) {
        url = Http.imageHost + url;
    }
    Bitmap bitmap = getBitmapFromCache(url);
    this.current = context;
    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        LayoutParams lp = imageView.getLayoutParams();
        lp.height = Util.DiptoPx(this.current, bitmap.getHeight());
        lp.width = Util.DiptoPx(this.current, bitmap.getWidth());
        imageView.setLayoutParams(lp);
        imageView.setImageBitmap(bitmap);
    }
}

From source file:com.teitsmch.hearthmaker.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.navigation_drawer, menu);

    final MenuItem item = menu.findItem(R.id.action_search);
    //item.setActionView(R.layout.iv_rotate);
    //ImageView refresh = (ImageView) item.getActionView();
    final ImageView image = new ImageView(this);
    ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(
            ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT);
    image.setLayoutParams(layoutParams);
    image.setImageResource(R.drawable.ic_filter_list_24dp);
    int padding_in_dp = 16;
    final float scale = getResources().getDisplayMetrics().density;
    int padding_in_px = (int) (padding_in_dp * scale + 0.5f);
    image.setPadding(padding_in_px, 0, padding_in_px, 0);

    image.setOnClickListener(new View.OnClickListener() {
        @Override/*from   w w w  . ja v a 2s. com*/
        public void onClick(View v) {
            if (mSpinnerView.getVisibility() == View.VISIBLE)
                image.setImageResource(R.drawable.rev_ic_filter_list_24dp);
            else
                image.setImageResource(R.drawable.ic_filter_list_24dp);

            onOptionsItemSelected(item);
        }
    });
    item.setActionView(image);

    if (mFragment.getClass() == CardViewFragment.class) {
        menu.findItem(MENU_ITEM_RENAME).setVisible(false);
        menu.findItem(MENU_ITEM_CLEAR).setVisible(false);
        menu.findItem(MENU_ITEM_DELETE).setVisible(false);
        menu.findItem(R.id.class_icon).setVisible(false);
    } else {
        menu.findItem(MENU_ITEM_RENAME).setVisible(true);
        menu.findItem(MENU_ITEM_CLEAR).setVisible(true);
        menu.findItem(MENU_ITEM_DELETE).setVisible(true);
        menu.findItem(R.id.class_icon).setVisible(true);
        menu.findItem(R.id.class_icon).setIcon(classIcon);
    }

    return super.onCreateOptionsMenu(menu);
}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

private void addRedDotTab(final int position, String title, int resId) {
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.HORIZONTAL);
    tabLayout.setGravity(Gravity.CENTER);
    TextView tab = new TextView(getContext());
    tab.setText(title);/* ww w.j a  v  a  2 s.c  o m*/
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);

    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(R.color.pst_tab_text_selector));
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
    tabLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mOnPageClickedLisener) {
                mOnPageClickedLisener.onPageClicked(position);
            }
            pager.setCurrentItem(position);
        }
    });

    tabLayout.addView(tab, 0);
    ImageView tabImg = new ImageView(getContext());
    LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    tabImgParams.setMargins(DeviceUtils.dip2px(getContext(), 5), DeviceUtils.dip2px(getContext(), 10), 0, 0);
    tabImgParams.gravity = Gravity.TOP;
    tabImg.setLayoutParams(tabImgParams);

    tabLayout.addView(tabImg, 1);
    tabsContainer.addView(tabLayout);
}