本文整理汇总了Java中android.support.v7.widget.AppCompatImageView.setImageResource方法的典型用法代码示例。如果您正苦于以下问题:Java AppCompatImageView.setImageResource方法的具体用法?Java AppCompatImageView.setImageResource怎么用?Java AppCompatImageView.setImageResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.AppCompatImageView
的用法示例。
在下文中一共展示了AppCompatImageView.setImageResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupUserAvatar
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
private void setupUserAvatar(AppCompatImageView avatar, Me.ProfileImage image) {
int flag = CalendarUtils.festivalFlag();
if (2 == flag) {
avatar.setImageResource(R.mipmap.new_year_round);
} else if (1 == flag) {
avatar.setImageResource(R.mipmap.new_year_dog2);
} else {
if (null == image) {
avatar.setImageResource(R.mipmap.bg_dark_avatar_male_big_normal);
} else {
RequestBuilder<Bitmap> bitmapRequestBuilder = GlideApp.with(getActivity())
.asBitmap()
.load(image.large)
.error(R.mipmap.bg_dark_avatar_male_big_normal)
.placeholder(R.mipmap.bg_dark_avatar_male_big_normal)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.fallback(R.mipmap.bg_dark_avatar_male_big_normal);
bitmapRequestBuilder.into(avatar);
}
}
}
示例2: prepareLayout
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
void prepareLayout() {
int layoutResource;
layoutResource = getLayoutResource();
inflate(getContext(), layoutResource, this);
setOrientation(VERTICAL);
setGravity(Gravity.CENTER_HORIZONTAL);
setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
iconView = (AppCompatImageView) findViewById(R.id.bb_bottom_bar_icon);
iconView.setImageResource(iconResId);
if (type != Type.TABLET) {
titleView = (TextView) findViewById(R.id.bb_bottom_bar_title);
titleView.setText(title);
}
updateCustomTextAppearance();
updateCustomTypeface();
}
示例3: addIconNormal
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
private void addIconNormal() {
View view = LayoutInflater.from(getContext()).inflate(R.layout.indicator_single_icon, holder, false);
view.setLayoutParams(getItemParams());
AppCompatImageView imageView = (AppCompatImageView) view.findViewById(R.id.ic_single);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
params.setMargins(indicatorAttr.eai_ic_margin, indicatorAttr.eai_ic_margin, indicatorAttr.eai_ic_margin, indicatorAttr.eai_ic_margin);
imageView.setLayoutParams(params);
if (iconNormalResId != 0)
imageView.setImageResource(iconNormalResId);
else
imageView.setImageDrawable(indicatorAttr.eai_ic_src);
imageView.invalidate();
holder.addView(view);
holder.invalidate();
}
示例4: init
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
private void init() {
// Inflating the background area
inflate(getContext(), R.layout.view_base_swipe, BaseSwipeActionView.this);
swipeContainer = findViewById(R.id.swipeContainer);
AppCompatImageView leftIconView = (AppCompatImageView) findViewById(R.id.leftIcon);
leftIconView.setImageResource(getLeftIconResId());
AppCompatImageView rightIconView = (AppCompatImageView) findViewById(R.id.rightIcon);
rightIconView.setImageResource(getRightIconResId());
// Inflating the foreground area
childContainer = (FrameLayout) findViewById(R.id.childContainer);
childContainer.setBackgroundColor(Color.CYAN);
LayoutInflater.from(getContext()).inflate(getOverlayLayoutResId(), childContainer, true);
childContainer.setOnClickListener(containerClickListenerWrapper);
minimumXtoHandleEvents = getResources().getDimension(R.dimen.dimen_swipe_minumum_x);
if (isSwipeEnabled()) {
initGestureDetector();
}
}
示例5: init
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
mImageHeart = new AppCompatImageView(context);
TypedArray a = context.getTheme().obtainStyledAttributes(
attrs,
R.styleable.InstaLikeView,
defStyleAttr, 0);
int likeColor = a.getColor(R.styleable.InstaLikeView_likeColor, ContextCompat.getColor(context, R.color.heartColor));
int likeSrc = a.getResourceId(R.styleable.InstaLikeView_likeSrc, R.drawable.img_heart);
int likeSize = a.getDimensionPixelSize(R.styleable.InstaLikeView_likeSize, getResources().getDimensionPixelSize(R.dimen.likeSize));
LayoutParams heartParams = new LayoutParams(likeSize, likeSize);
heartParams.addRule(CENTER_IN_PARENT, TRUE);
mImageHeart.setLayoutParams(heartParams);
mImageHeart.setVisibility(GONE);
mImageHeart.setImageResource(likeSrc);
mImageHeart.setColorFilter(likeColor);
addView(mImageHeart);
}
示例6: cooking
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
public static @CheckResult Toast cooking(Context context, CharSequence message_to_show, int text_color, int background, int icon_toast, boolean duration) {
View view = ((LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.cooking_a_toast, null);
view.setBackgroundColor(background);
AppCompatImageView icon = (AppCompatImageView) view.findViewById(R.id.icon);
icon.setImageResource(icon_toast);
AppCompatTextView message = (AppCompatTextView) view.findViewById(R.id.message);
message.setText(message_to_show);
message.setTextColor(text_color);
Toast toast = new Toast(context);
toast.setView(view);
toast.setGravity(Gravity.FILL_HORIZONTAL | Gravity.BOTTOM, 0, 0);
if (duration) {
toast.setDuration(Toast.LENGTH_LONG);
} else {
toast.setDuration(Toast.LENGTH_SHORT);
}
return toast;
}
示例7: prepareLayout
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
void prepareLayout() {
inflate(getContext(), getLayoutResource(), this);
setOrientation(VERTICAL);
setGravity(isTitleless? Gravity.CENTER : Gravity.CENTER_HORIZONTAL);
setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
setBackgroundResource(MiscUtils.getDrawableRes(getContext(), R.attr.selectableItemBackgroundBorderless));
iconView = (AppCompatImageView) findViewById(R.id.bb_bottom_bar_icon);
iconView.setImageResource(iconResId);
if (type != Type.TABLET && !isTitleless) {
titleView = (TextView) findViewById(R.id.bb_bottom_bar_title);
titleView.setVisibility(VISIBLE);
if (type == Type.SHIFTING) {
findViewById(R.id.spacer).setVisibility(VISIBLE);
}
updateTitle();
}
updateCustomTextAppearance();
updateCustomTypeface();
}
示例8: setUpTabView
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
void setUpTabView(int position, View tabView) {
TextView title = (TextView) tabView.findViewById(R.id.text_view);
AppCompatImageView image = (AppCompatImageView) tabView.findViewById(R.id.image_view);
switch (position) {
case 0:
title.setText(String.format(Locale.getDefault(), "%d", event.getConfirms()));
title.setTextColor(ContextCompat.getColor(UserReportsDetailsActivity.this, R.color.green_confirmation));
image.setImageResource(R.drawable.cara_cierto);
break;
case 1:
title.setText(String.format(Locale.getDefault(), "%d", event.getDeclines()));
title.setTextColor(ContextCompat.getColor(UserReportsDetailsActivity.this, R.color.red_declination));
image.setImageResource(R.drawable.cara_falso);
break;
}
}
示例9: init
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
private void init() {
inflate(getContext(), R.layout.recycle_picker, this);
titlePickerTv = findViewById(R.id.titlePickerTv);
subTitleTv = findViewById(R.id.subTitleTv);
AppCompatImageView numberImgv = findViewById(R.id.numberImgv);
recyclerView = findViewById(R.id.recyclerView);
titlePickerTv.setText(title);
titlePickerTv.setTextColor(titleColor);
subTitleTv.setTextColor(subColor);
titlePickerTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, titleSize);
subTitleTv.setTextSize(TypedValue.COMPLEX_UNIT_SP, subSize);
numberImgv.getLayoutParams().width = itemSize;
numberImgv.getLayoutParams().height = itemSize;
numberImgv.setImageResource(pickerIcon);
itemWidth = itemSize;
initialView();
}
示例10: addItem
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
public BottomGridSheetBuilder addItem(int imageRes, CharSequence text, Object tag, @Style int style, int subscriptRes) {
LayoutInflater inflater = LayoutInflater.from(mContext);
// 给机会让用的人自定义ItemView
LinearLayout itemView = (LinearLayout) inflater.inflate(R.layout.qmui_bottom_sheet_grid_item, null, false);
// 字体加粗
TextView titleTV = (TextView) itemView.findViewById(R.id.grid_item_title);
if(mItemTextTypeFace != null){
titleTV.setTypeface(mItemTextTypeFace);
}
titleTV.setText(text);
itemView.setTag(tag);
itemView.setOnClickListener(this);
AppCompatImageView imageView = (AppCompatImageView) itemView.findViewById(R.id.grid_item_image);
imageView.setImageResource(imageRes);
if (subscriptRes != 0) {
ViewStub stub = (ViewStub) itemView.findViewById(R.id.grid_item_subscript);
View inflated = stub.inflate();
((ImageView) inflated).setImageResource(subscriptRes);
}
switch (style) {
case FIRST_LINE:
mFirstLineViews.append(mFirstLineViews.size(), itemView);
break;
case SECOND_LINE:
mSecondLineViews.append(mSecondLineViews.size(), itemView);
break;
}
return this;
}
示例11: addIconCurrent
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
private void addIconCurrent() {
currentIconView = (RelativeLayout) LayoutInflater.from(getContext()).inflate(R.layout.indicator_single_icon, this, false);
currentIconView.setLayoutParams(getItemParams());
AppCompatImageView imageView = (AppCompatImageView) currentIconView.findViewById(R.id.ic_single);
RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
params.setMargins(indicatorAttr.eai_ic_current_margin, indicatorAttr.eai_ic_current_margin, indicatorAttr.eai_ic_current_margin, indicatorAttr.eai_ic_current_margin);
imageView.setLayoutParams(params);
if (iconSelectedResId != 0)
imageView.setImageResource(iconSelectedResId);
else
imageView.setImageDrawable(indicatorAttr.eai_ic_current_src);
imageView.invalidate();
tempView = (RelativeLayout) LayoutInflater.from(getContext()).inflate(R.layout.indicator_single_icon, this, false);
tempView.setLayoutParams(getItemParams());
AppCompatImageView imageView2 = (AppCompatImageView) tempView.findViewById(R.id.ic_single);
imageView2.setLayoutParams(params);
if (iconSelectedResId != 0)
imageView2.setImageResource(iconSelectedResId);
else
imageView2.setImageDrawable(indicatorAttr.eai_ic_current_src);
imageView2.invalidate();
addView(currentIconView);
addView(tempView);
invalidate();
}
示例12: perform
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
public void perform(View view) {
switch (view.getId()) {
case R.id.frag_oval_menu_add_long_btn: {
mOvalMenu.setAAxisPercentByHalfWidth(mOvalMenu.getAAxisPercentByHalfWidth() + 0.1F);
break;
}
case R.id.frag_oval_menu_sub_long_btn: {
mOvalMenu.setAAxisPercentByHalfWidth(mOvalMenu.getAAxisPercentByHalfWidth() - 0.1F);
break;
}
case R.id.frag_oval_menu_add_short_btn: {
mOvalMenu.setBAxisPercentByAAxis(mOvalMenu.getBAxisPercentByAAxis() + 0.1F);
break;
}
case R.id.frag_oval_menu_sub_short_btn: {
mOvalMenu.setBAxisPercentByAAxis(mOvalMenu.getBAxisPercentByAAxis() - 0.1F);
break;
}
case R.id.frag_oval_menu_hide_show_btn: {
mOvalMenu.setDebug(!mOvalMenu.isDebug());
break;
}
case R.id.frag_oval_menu_remove_all_btn: {
mOvalMenu.removeAllViews();
break;
}
case R.id.frag_oval_menu_add_btn: {
AppCompatImageView appCompatImageView = new AppCompatImageView(getContext());
appCompatImageView.setImageResource(R.drawable.girl);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
mOvalMenu.addView(appCompatImageView, params);
break;
}
case R.id.frag_oval_menu_sub_btn: {
if (mOvalMenu.getChildCount() > 0)
mOvalMenu.removeViewAt(mRandom.nextInt(mOvalMenu.getChildCount()));
break;
}
}
}
示例13: addArcAnimation
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
/**
* Add arc above/below the circular target overlay.
*/
private void addArcAnimation(final Activity activity) {
AppCompatImageView mImageView = new AppCompatImageView(activity);
mImageView.setImageResource(R.drawable.ic_spotlight_arc);
LayoutParams params = new LayoutParams(2 * (circleShape.getRadius() + extraPaddingForArc),
2 * (circleShape.getRadius() + extraPaddingForArc));
if (targetView.getPoint().y > getHeight() / 2) {//bottom
if (targetView.getPoint().x > getWidth() / 2) {//Right
params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
} else {
params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
}
} else {//up
mImageView.setRotation(180); //Reverse the view
if (targetView.getPoint().x > getWidth() / 2) {//Right
params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
} else {
params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
}
}
mImageView.postInvalidate();
mImageView.setLayoutParams(params);
addView(mImageView);
PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(lineAndArcColor,
PorterDuff.Mode.SRC_ATOP);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AnimatedVectorDrawable avd = (AnimatedVectorDrawable)
ContextCompat.getDrawable(activity, R.drawable.avd_spotlight_arc);
avd.setColorFilter(porterDuffColorFilter);
mImageView.setImageDrawable(avd);
avd.start();
} else {
AnimatedVectorDrawableCompat avdc =
AnimatedVectorDrawableCompat.create(activity, R.drawable.avd_spotlight_arc);
avdc.setColorFilter(porterDuffColorFilter);
mImageView.setImageDrawable(avdc);
avdc.start();
}
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
addPathAnimation(activity);
}
}, 400);
}
示例14: initBackground
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
private void initBackground(AttributeSet attrs, int defStyle) {
mPlanetView = new AppCompatImageView(getContext());
mStarView = new AppCompatImageView(getContext());
final LinearLayout.LayoutParams mParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
mStarView.setLayoutParams(mParams);
addView(mStarView);
mStarView.setAlpha(0f);
mStarDrawable = new ParticlesDrawable();
mStarDrawable.setStepMultiplier(0.5f);
//mStarDrawable.setFrameDelay(2000);
mStarDrawable.setLineVisibility(false);
if(Build.VERSION.SDK_INT >= 16) {
mStarView.setBackground(mStarDrawable);
} else {
mStarView.setBackgroundDrawable(mStarDrawable);
}
mStarView.setImageResource(R.drawable.alpha_gradient);
TypedArray mArray;
if(defStyle == 0) {
mArray = getContext().obtainStyledAttributes(attrs, R.styleable.SkyTimeBackgroundView);
} else {
mArray = getContext().obtainStyledAttributes(attrs, R.styleable.SkyTimeBackgroundView, defStyle, 0);
}
isAutoStart = mArray.getBoolean(R.styleable.SkyTimeBackgroundView_autoStart, false);
isPlanetAnimationOn = mArray.getBoolean(R.styleable.SkyTimeBackgroundView_planetAnimation, false);
isPlanetVisible = mArray.getBoolean(R.styleable.SkyTimeBackgroundView_planetVisible, true);
isStarVisible = mArray.getBoolean(R.styleable.SkyTimeBackgroundView_starVisible, true);
if(mArray.getString(R.styleable.SkyTimeBackgroundView_starLineVisible) != null) {
if(mArray.getString(R.styleable.SkyTimeBackgroundView_starLineVisible).equals("auto")) {
isStarLineVisible = mArray.getBoolean(R.styleable.SkyTimeBackgroundView_starLineVisible, true);
isStarLineVisibleAuto = true;
}
} else{
isStarLineVisible = mArray.getBoolean(R.styleable.SkyTimeBackgroundView_starLineVisible, true);
isStarLineVisibleAuto = false;
}
String s = mArray.getString(R.styleable.SkyTimeBackgroundView_planetType);
if(s != null) {
switch (s) {
case SUN:
mPlanetType = SUN;
break;
case RED_SUN:
mPlanetType = RED_SUN;
break;
case MOON:
mPlanetType = MOON;
break;
}
} else {
mPlanetType = SUN;
}
planetPosition = mArray.getInt(R.styleable.SkyTimeBackgroundView_planetPosition, 0);
mPlanetSpeed = mArray.getInt(R.styleable.SkyTimeBackgroundView_planetSpeed, 300);
mAnimationIndex = planetPosition;
mArray.recycle();
if(mPlanetType.equals(SUN)) {
setTime(Time.AFTERNOON);
} else if(mPlanetType.equals(RED_SUN)) {
setTime(Time.EARLY_NIGHT);
} else if(mPlanetType.equals(MOON)) {
setTime(Time.NIGHT);
}
mPainter = new SkyViewGradientBackgroundPainter(this, mDrawables);
}
示例15: addArcAnimation
import android.support.v7.widget.AppCompatImageView; //导入方法依赖的package包/类
/**
* Add arc above/below the circular target overlay.
*/
private void addArcAnimation(final Activity activity) {
AppCompatImageView mImageView = new AppCompatImageView(activity);
mImageView.setImageResource(R.drawable.ic_spotlight_arc);
LayoutParams params = new LayoutParams(2 * (circleShape.getRadius() + extraPaddingForArc),
2 * (circleShape.getRadius() + extraPaddingForArc));
if (targetView.getPoint().y > getHeight() / 2) {//bottom
if (targetView.getPoint().x > getWidth() / 2) {//Right
params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
} else {
params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
}
} else {//up
mImageView.setRotation(180); //Reverse the view
if (targetView.getPoint().x > getWidth() / 2) {//Right
params.rightMargin = getWidth() - targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.RIGHT | Gravity.BOTTOM;
} else {
params.leftMargin = targetView.getPoint().x - circleShape.getRadius() - extraPaddingForArc;
params.bottomMargin = getHeight() - targetView.getPoint().y - circleShape.getRadius() - extraPaddingForArc;
params.gravity = Gravity.LEFT | Gravity.BOTTOM;
}
}
mImageView.postInvalidate();
mImageView.setLayoutParams(params);
addView(mImageView);
PorterDuffColorFilter porterDuffColorFilter = new PorterDuffColorFilter(lineAndArcColor,
PorterDuff.Mode.SRC_ATOP);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AnimatedVectorDrawable avd = (AnimatedVectorDrawable)
ContextCompat.getDrawable(activity, R.drawable.avd_spotlight_arc);
avd.setColorFilter(porterDuffColorFilter);
mImageView.setImageDrawable(avd);
avd.start();
} else {
AnimatedVectorDrawableCompat avdc =
AnimatedVectorDrawableCompat.create(activity, R.drawable.avd_spotlight_arc);
avdc.setColorFilter(porterDuffColorFilter);
mImageView.setImageDrawable(avdc);
avdc.start();
}
new Handler(Looper.getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
addPathAnimation(activity);
}
}, 400);
}