Java Code Examples for android.widget.ImageView#setLayoutParams()

The following examples show how to use android.widget.ImageView#setLayoutParams() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public void updateOnView(List<ScaleMeasurement> scaleMeasurementList)
{
    tableHeaderView.removeAllViews();

    final int iconHeight = pxImageDp(20);
    ArrayList<MeasurementView> visibleMeasurements = new ArrayList<>();

    for (MeasurementView measurement : measurementViews) {
        if (!measurement.isVisible() || measurement instanceof UserMeasurementView) {
            continue;
        }


        ImageView headerIcon = new ImageView(tableView.getContext());
        headerIcon.setImageDrawable(measurement.getIcon());
        headerIcon.setColorFilter(ColorUtil.getTintColor(tableView.getContext()));
        headerIcon.setLayoutParams(new TableRow.LayoutParams(0, iconHeight, 1));
        headerIcon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);

        tableHeaderView.addView(headerIcon);

        visibleMeasurements.add(measurement);
    }

    adapter.setMeasurements(visibleMeasurements, scaleMeasurementList);
}
 
Example 2
Source Project: Pigeon   File: GuidePageActivity.java    License: MIT License 6 votes vote down vote up
private void initViewPager() {
    vp = (ViewPager) findViewById(R.id.guide_vp);
    //实例化图片资源
    imageIdArray = new int[]{R.drawable.bg_guide_family, R.drawable.bg_guide_notes, R.drawable.bg_guide_weather, R.drawable.bg_guide_rebot};
    viewList = new ArrayList<>();
    //获取一个Layout参数,设置为全屏
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT);

    //循环创建View并加入到集合中
    int len = imageIdArray.length;
    for (int i = 0; i < len; i++) {
        //new ImageView并设置全屏和图片资源
        ImageView imageView = new ImageView(this);
        imageView.setLayoutParams(params);
        imageView.setBackgroundResource(imageIdArray[i]);

        //将ImageView加入到集合中
        viewList.add(imageView);
    }

    //View集合初始化好后,设置Adapter
    vp.setAdapter(new GuidePageAdapter(viewList));
    //设置滑动监听
    vp.setOnPageChangeListener(this);
}
 
Example 3
/**
 * Splash screen is shown both before the Trusted Web Activity is launched - in this activity,
 * and for some time after that - in browser, on top of web page being loaded.
 * This method shows the splash screen in the LauncherActivity.
 */
private void showSplashScreen() {
    mSplashImage = Utils.convertDrawableToBitmap(mActivity, mDrawableId);
    if (mSplashImage == null) {
        Log.w(TAG, "Failed to retrieve splash image from provided drawable id");
        return;
    }
    ImageView view = new ImageView(mActivity);
    view.setLayoutParams(new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));
    view.setImageBitmap(mSplashImage);
    view.setBackgroundColor(mBackgroundColor);

    view.setScaleType(mScaleType);
    if (mScaleType == ImageView.ScaleType.MATRIX) {
        view.setImageMatrix(mTransformationMatrix);
    }

    mActivity.setContentView(view);
}
 
Example 4
Source Project: AndroidAnimationsActions   File: MainActivity.java    License: MIT License 6 votes vote down vote up
@OnClick(R.id.playFirstAnim)
protected void playFirstAnimation() {
    firstAnimContainer.removeAllViews();
    secondAnimContainer.removeAllViews();
    for (int i = 0; i < 6; i++) {
        int size = getResources().getDimensionPixelSize(R.dimen.circle_size);
        int margin = getResources().getDimensionPixelSize(R.dimen.circle_margin);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(size, size);
        params.leftMargin = margin;
        params.rightMargin = margin;
        params.gravity = Gravity.CENTER;
        ImageView view = new ImageView(this);
        view.setLayoutParams(params);
        view.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.circle));
        float delay = random.nextFloat();
        float targetY = random.nextInt((int) (firstAnimContainer.getBottom() / 4f));
        play(sequence(fadeOut(), scaleTo(1.5f, 1.5f), fadeIn(2), delay(delay),
                parallel(moveBy(0, targetY, 2, Interpolations.ElasticEaseOut), sequence(color(-1, Color.GREEN, 1), color(Color.GREEN, Color.RED, 1)),
                        scaleTo(1, 1, 2, Interpolations.ElasticEaseOut))), view);
        firstAnimContainer.addView(view);
    }
}
 
Example 5
public ItemView(Context context) {
    super(context);
    setOrientation(HORIZONTAL);
    setGravity(Gravity.CENTER_VERTICAL);
    mIcon = new ImageView(context);
    int iconSize = (int) ResTools.getDimen(R.dimen.icon_size);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(iconSize, iconSize);
    lp.rightMargin = (int)ResTools.getDimen(R.dimen.hor_padding);
    mIcon.setLayoutParams(lp);
    addView(mIcon);

    int textsize = (int)ResTools.getDimen(R.dimen.textsize2);
    mAppName = new TextView(context);
    mAppName.setTextSize(TypedValue.COMPLEX_UNIT_PX, textsize);
    mAppName.setTextColor(ResTools.getColor(R.color.text));
    lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.weight = 1;
    addView(mAppName, lp);

    setMinimumHeight((int)ResTools.getDimen(R.dimen.item_height));

    int hp = (int)ResTools.getDimen(R.dimen.hor_padding);
    int vp = (int)ResTools.getDimen(R.dimen.vtl_padding);
    setPadding(hp,vp,hp,vp);
}
 
Example 6
@Override
protected void onCreate(Bundle state) {
	super.onCreate(state);

	setRequestedOrientation(SCREEN_ORIENTATION_NOSENSOR);

	getSupportActionBar().hide();

	String qrData = getIntent().getStringExtra(Intent.EXTRA_TEXT);

	ImageView qrCodeView = new ImageView(this);

	qrCodeView.setScaleType(FIT_CENTER);
	qrCodeView.setBackgroundColor(WHITE);
	qrCodeView.setLayoutParams(new LayoutParams(MATCH_PARENT,
			MATCH_PARENT, 1f));

	Display display = getWindowManager().getDefaultDisplay();
	boolean portrait = display.getWidth() < display.getHeight();
	layoutMain = new LinearLayout(this);
	if(portrait) layoutMain.setOrientation(VERTICAL);
	else layoutMain.setOrientation(HORIZONTAL);
	layoutMain.setWeightSum(1);
	layoutMain.addView(qrCodeView);
	setContentView(layoutMain);

	new QrGenAsyncTask(this, qrCodeView, 240).executeOnExecutor(ImApp.sThreadPoolExecutor,qrData);
}
 
Example 7
private void createLayout() {
    LinearLayout baseLayout = new LinearLayout(this);
    baseLayout.setOrientation(LinearLayout.VERTICAL);
    baseLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    baseLayout.setGravity(Gravity.BOTTOM);
    setContentView(baseLayout);

    ImageView wallPreview = new ImageView(this);
    wallPreview.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
    wallPreview.setScaleType(ImageView.ScaleType.CENTER_CROP);
    wallPreview.setImageBitmap(wallpaper);
    baseLayout.addView(wallPreview);

    LinearLayout buttonBar = new LinearLayout(this);
    buttonBar.setOrientation(LinearLayout.HORIZONTAL);
    buttonBar.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, Math.round(96 * scale)));
    baseLayout.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.colorPrimary));
    buttonBar.setGravity(Gravity.CENTER);
    buttonBar.setBackgroundColor(getResources().getColor(R.color.colorLight));
    baseLayout.addView(buttonBar);

    ImageView backButton = new ImageView(this);
    backButton.setLayoutParams(new LinearLayout.LayoutParams(0, Math.round(72 * scale), 1));
    backButton.setImageBitmap(ImageUtils.bitmapLoad(getApplicationContext().getResources(), R.drawable.ic_close, Math.round(72 * scale), Math.round(72 * scale)));
    buttonBar.addView(backButton);
    backButton.setOnClickListener(v -> finish());

    ImageView applyButton = new ImageView(this);
    applyButton.setLayoutParams(new LinearLayout.LayoutParams(0, Math.round(72 * scale), 1));
    applyButton.setImageBitmap(ImageUtils.bitmapLoad(getApplicationContext().getResources(), R.drawable.ic_apply, Math.round(72 * scale), Math.round(72 * scale)));
    buttonBar.addView(applyButton);
    applyButton.setOnClickListener(this::setWallpaper);
}
 
Example 8
Source Project: ImageLoader   File: AlbumAdapter.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void convert(@NonNull final BaseViewHolder helper, final Album item) {
    helper.getView(R.id.item_iv).setTag(R.id.item_iv,item);
    ImageView imageView = helper.getView(R.id.item_iv);
    imageView.setAdjustViewBounds(false);
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
    params.height = imageView.getContext().getResources().getDisplayMetrics().widthPixels/2;
    imageView.setLayoutParams(params);

    ImageLoader.with(helper.itemView.getContext())
            .file(item.cover)
            .scale(ScaleMode.CENTER_CROP)
            .loading(R.drawable.iv_loading_trans)
            .error(R.drawable.im_item_list_opt_error)
            .into(imageView);
    helper.setText(R.id.tv_info,item.name);
    helper.getConvertView().setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ImageListView listView = new ImageListView(v.getContext());
            ImageMediaCenterUtil.showViewAsDialog(listView);
            listView.showImagesInAlbum(item);
        }
    });





}
 
Example 9
public PersonRenderer() {
    super(getApplicationContext(), getMap(), mClusterManager);

    View multiProfile = getLayoutInflater().inflate(R.layout.multi_profile, null);
    mClusterIconGenerator.setContentView(multiProfile);
    mClusterImageView = multiProfile.findViewById(R.id.image);

    mImageView = new ImageView(getApplicationContext());
    mDimension = (int) getResources().getDimension(R.dimen.custom_profile_image);
    mImageView.setLayoutParams(new ViewGroup.LayoutParams(mDimension, mDimension));
    int padding = (int) getResources().getDimension(R.dimen.custom_profile_padding);
    mImageView.setPadding(padding, padding, padding, padding);
    mIconGenerator.setContentView(mImageView);
}
 
Example 10
@Override
public Presenter.ViewHolder onCreateViewHolder(ViewGroup parent) {
    ImageView imageView = (ImageView) LayoutInflater.from(parent.getContext())
            .inflate(R.layout.lb_fullwidth_details_overview_logo, parent, false);

    Resources res = parent.getResources();
    int width = res.getDimensionPixelSize(R.dimen.detail_thumb_width);
    int height = res.getDimensionPixelSize(R.dimen.detail_thumb_height);
    imageView.setLayoutParams(new ViewGroup.MarginLayoutParams(width, height));
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);

    return new ViewHolder(imageView);
}
 
Example 11
Source Project: PeriscopeLayout   File: PeriscopeLayout.java    License: Apache License 2.0 5 votes vote down vote up
public void addHeart() {

        ImageView imageView = new ImageView(getContext());
        //随机选一个
        imageView.setImageDrawable(drawables[random.nextInt(3)]);
        imageView.setLayoutParams(lp);

        addView(imageView);

        Animator set = getAnimator(imageView);
        set.addListener(new AnimEndListener(imageView));
        set.start();

    }
 
Example 12
Source Project: Yuan-SxMusic   File: DiscView.java    License: Apache License 2.0 5 votes vote down vote up
private void initDiscImg() {
    ImageView mDiscBackground = findViewById(R.id.iv_disc_background);
    mObjectAnimator=getDiscObjectAnimator(mDiscBackground);
    mDiscBackground.setImageDrawable(getDiscDrawable(
            BitmapFactory.decodeResource(getResources(),R.drawable.default_disc)
    ));


    int marginTop = (int) (DisplayUtil.SCALE_DISC_MARGIN_TOP * mScreenHeight);
    LayoutParams layoutParams = (LayoutParams) mDiscBackground
            .getLayoutParams();
    layoutParams.setMargins(0, marginTop, 0, 0);

    mDiscBackground.setLayoutParams(layoutParams);
}
 
Example 13
/**
 * Creates a blank space to fill the row.
 *
 * @return the view with the blank space.
 */
@NonNull
private ImageView createBlankSpace() {
	ImageView view = new ImageView(getContext());
	TableRow.LayoutParams params = new TableRow.LayoutParams(mSwatchLength, mSwatchLength);
	params.setMargins(mMarginSize, mMarginSize, mMarginSize, mMarginSize);
	view.setLayoutParams(params);
	return view;
}
 
Example 14
Source Project: PickerUI   File: PickerUIBlurHelper.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a ImageView with width and height MATCH_PARENT, which will host the blurred snapshot.
 */
private void createImageViewBlur() {

    if (mUseBlur) {
        mRootView = (ViewGroup) ((Activity) mContext).getWindow().getDecorView()
                .findViewById(android.R.id.content);

        mBlurredImageView = new ImageView(mContext);

        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);

        Log.d("YYYYY width", "" + mRootView.getWidth());
        Log.d("YYYYY height", "" + mRootView.getHeight());
        mBlurredImageView.setLayoutParams(params);
        mBlurredImageView.setClickable(false);
        mBlurredImageView.setVisibility(View.GONE);
        mBlurredImageView.setScaleType(ImageView.ScaleType.FIT_XY);

        mRootView.post(new Runnable() {
            @Override
            public void run() {
                // Add the ImageView with blurred view
                ((ViewGroup) mRootView.getChildAt(0))
                        .addView(mBlurredImageView, mRootView.getChildCount());
            }
        });
    }
}
 
Example 15
@BindingAdapter("android:layout_height")
public static void setLayoutHeight(@NonNull ImageView view, @NonNull @Dimension float dimen) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    params.width = (int)dimen;
    view.setLayoutParams(params);
}
 
Example 16
Source Project: fridge   File: ContestsListFragment.java    License: MIT License 4 votes vote down vote up
@Override
public void onPrepareOptionsMenu(Menu menu) {

    searchView = (android.support.v7.widget.SearchView) menu.findItem(R.id.action_search).getActionView();
    searchView.setIconifiedByDefault(false);
    searchView.setIconified(false);
    searchView.setQueryHint("Enter contest name or code");
    searchView.setQuery(filter, true);
    View v = searchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    if (v != null)
        v.setBackgroundColor(Color.TRANSPARENT);


    android.support.v7.widget.SearchView.SearchAutoComplete searchAutoComplete = searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text);
    searchAutoComplete.setTextColor(Color.WHITE);
    searchAutoComplete.setHintTextColor(Color.LTGRAY);

    searchView.setBackground(getResources().getDrawable(R.drawable.search_bar_bg));


    ImageView searchIcon = searchView.findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
    searchIcon.setLayoutParams(new LinearLayout.LayoutParams(0, 0));
    searchView.setOnQueryTextListener(new android.support.v7.widget.SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {

            contestsListAdapter.setFilter(query);
            filter = query;
            return true;

        }

        @Override
        public boolean onQueryTextChange(String newText) {
            contestsListAdapter.setFilter(newText);
            filter = newText;
            return true;
        }
    });
    searchView.clearFocus();
}
 
Example 17
private View createBackView() {
    ImageView backView = new ImageView(mContext);
    backView.setImageDrawable(VenvyResourceUtil.getDrawable(mContext, "img_scanner_btn_back"));
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
    params.leftMargin = VenvyUIUtil.dip2px(mContext, 10);

    backView.setLayoutParams(params);

    backView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mGridView != null) {
                removeView(mGridView);
                imageModel.onDestroy();
                imageModel = null;
                mGridView = null;
                imageItemAdapter = null;
                mListView.setVisibility(VISIBLE);
                mCancelView.setVisibility(GONE);
                mTitleView.setText("选择相册");
            } else {//关闭diaolog

                removeAllViews();
                if (imageModel != null) {
                    imageModel.onDestroy();
                    imageModel = null;
                }
                mGridView = null;
                imageItemAdapter = null;
                mListView = null;
                if (imageFolderModel != null) {
                    imageFolderModel.onDestroy();
                    imageFolderModel = null;
                }
                imageFloderAdapter = null;
                if (mDismissDialogListener != null) {
                    mDismissDialogListener.onClick(null);
                }
            }

        }
    });
    return backView;

}
 
Example 18
Source Project: glide-support   File: ImageChunkAdapter.java    License: The Unlicense 4 votes vote down vote up
@Override public ImageChunkViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
	ImageView view = new ImageView(parent.getContext());
	view.setScaleType(ScaleType.CENTER);
	view.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, (int)(imageChunkHeight * ratio)));
	return new ImageChunkViewHolder(view);
}
 
Example 19
Source Project: likequanmintv   File: CommonTabLayout.java    License: Apache License 2.0 4 votes vote down vote up
private void updateTabStyles() {
        for (int i = 0; i < mTabCount; i++) {
            View tabView = mTabsContainer.getChildAt(i);
            tabView.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            TextView tv_tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
            tv_tab_title.setTextColor(i == mCurrentTab ? mTextSelectColor : mTextUnselectColor);
            tv_tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextsize);
//            tv_tab_title.setPadding((int) mTabPadding, 0, (int) mTabPadding, 0);
            if (mTextAllCaps) {
                tv_tab_title.setText(tv_tab_title.getText().toString().toUpperCase());
            }

            if (mTextBold == TEXT_BOLD_BOTH) {
                tv_tab_title.getPaint().setFakeBoldText(true);
            } else if (mTextBold == TEXT_BOLD_NONE) {
                tv_tab_title.getPaint().setFakeBoldText(false);
            }

            ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);
            if (mIconVisible) {
                iv_tab_icon.setVisibility(View.VISIBLE);
                CustomTabEntity tabEntity = mTabEntitys.get(i);
                iv_tab_icon.setImageResource(i == mCurrentTab ? tabEntity.getTabSelectedIcon() : tabEntity.getTabUnselectedIcon());
                LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                        mIconWidth <= 0 ? LinearLayout.LayoutParams.WRAP_CONTENT : (int) mIconWidth,
                        mIconHeight <= 0 ? LinearLayout.LayoutParams.WRAP_CONTENT : (int) mIconHeight);
                if (mIconGravity == Gravity.LEFT) {
                    lp.rightMargin = (int) mIconMargin;
                } else if (mIconGravity == Gravity.RIGHT) {
                    lp.leftMargin = (int) mIconMargin;
                } else if (mIconGravity == Gravity.BOTTOM) {
                    lp.topMargin = (int) mIconMargin;
                } else {
                    lp.bottomMargin = (int) mIconMargin;
                }

                iv_tab_icon.setLayoutParams(lp);
            } else {
                iv_tab_icon.setVisibility(View.GONE);
            }
        }
    }
 
Example 20
Source Project: faceswap   File: IPSettingActivity.java    License: Apache License 2.0 4 votes vote down vote up
private void addPersonUIRow(final SharedPreferences mSharedPreferences, final int type,
                            final String name, String ip) {
    final TableLayout tb=tbs[type];

    //create a new table row
    final TableRow tr = new TableRow(this);
    TableRow.LayoutParams trTlp = new TableRow.LayoutParams(
            0,
            TableLayout.LayoutParams.WRAP_CONTENT
    );
    tr.setLayoutParams(trTlp);

    //create name view
    TextView nameView = new TextView(this);
    nameView.setText(name);
    nameView.setTextSize(20);
    TableRow.LayoutParams tlp1 = new TableRow.LayoutParams(
            TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.MATCH_PARENT
    );
    tlp1.column=0;
    nameView.setLayoutParams(tlp1);

    //create sub view
    TextView subView = new TextView(this);
    subView.setText(ip);
    subView.setTextSize(20);
    TableRow.LayoutParams tlp3 = new TableRow.LayoutParams(
            TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.MATCH_PARENT
    );
    tlp3.column=1;
    subView.setLayoutParams(tlp3);

    //create delete button
    ImageView deleteView = new ImageView(this);
    deleteView.setImageResource(R.drawable.ic_delete_black_24dp);
    TableRow.LayoutParams tlp4 = new TableRow.LayoutParams(
            TableLayout.LayoutParams.WRAP_CONTENT,
            TableLayout.LayoutParams.MATCH_PARENT
    );
    tlp4.column=2;
    deleteView.setLayoutParams(tlp4);
    deleteView.setOnClickListener(new ImageView.OnClickListener() {
        @Override
        public void onClick(View v) {
            //remove name from sharedPreferences
            String sharedPreferenceIpDictName=
                    getResources().getStringArray(R.array.shared_preference_ip_dict_names)[type];
            SharedPreferences.Editor editor = mSharedPreferences.edit();
            Set<String> existingNames =
                    new HashSet<String>(mSharedPreferences.getStringSet(sharedPreferenceIpDictName,
                            new HashSet<String>()));
            editor.remove(name);
            existingNames.remove(name);
            editor.putStringSet(sharedPreferenceIpDictName, existingNames);
            editor.commit();

            //remove current line from UI
            tb.removeView(tr);
        }
    });

    tr.addView(nameView);
    tr.addView(subView);
    tr.addView(deleteView);

    tb.addView(tr,
            new TableLayout.LayoutParams(TableLayout.LayoutParams.MATCH_PARENT,
                    TableLayout.LayoutParams.WRAP_CONTENT));
}