当前位置: 首页>>代码示例>>Java>>正文


Java ImageView.setImageResource方法代码示例

本文整理汇总了Java中android.widget.ImageView.setImageResource方法的典型用法代码示例。如果您正苦于以下问题:Java ImageView.setImageResource方法的具体用法?Java ImageView.setImageResource怎么用?Java ImageView.setImageResource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.widget.ImageView的用法示例。


在下文中一共展示了ImageView.setImageResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreateView

import android.widget.ImageView; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_photo_detail, container, false);

    mTitleView = (TextView) v.findViewById(R.id.photo_title);
    mTitleView.setText(getPhotoTitle(mPhoto));

    mImageView = (ImageView) v.findViewById(R.id.photo_image);
    if (mPhoto.getUrl() != null) {
        mApp.getImageDownloader(/*mImageView.getContext()*/)
                .load(mPhoto.getUrl())
                //.error(R.drawable.no_image)
                .into(mImageView);
    } else {
        mImageView.setImageResource(R.drawable.no_image);
    }

    mCaptionView = (TextView) v.findViewById(R.id.photo_caption);
    mCaptionView.setText(getPhotoCaption(mPhoto));

    return v;
}
 
开发者ID:approov,项目名称:hands-on-api-proxy,代码行数:23,代码来源:PhotoDetailFragment.java

示例2: imageDialog2

import android.widget.ImageView; //导入方法依赖的package包/类
public void imageDialog2(View view){
    AlertDialog.Builder builder;

    builder = new AlertDialog.Builder(this);

    ImageView imageView = new ImageView(this);

    imageView.setImageResource(R.drawable.step2);
    builder.setTitle("Clique em 'Novo projeto'...")
            .setView(imageView)
            .setNegativeButton("Voltar", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            })
            .show();
}
 
开发者ID:jvbeltra,项目名称:JavaIsFun,代码行数:18,代码来源:OQueEJava6.java

示例3: init

import android.widget.ImageView; //导入方法依赖的package包/类
private void init() {
    setOrientation(VERTICAL); //设置垂直布局
    setGravity(Gravity.CENTER); //中间对齐
    //初始化textView并添加
    contentView = new TextView(getContext());
    //添加行距
    contentView.setLineSpacing(1f, 1.3f);
    addView(contentView, LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
    //初始化ImageView并添加
    expandView = new ImageView(getContext());
    int padding = UIUtils.dp2px(getContext(), 5);
    expandView.setPadding(padding, padding, padding, padding);
    expandView.setImageResource(R.drawable.ic_arrow_down);
    LayoutParams llp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    addView(expandView, llp);
}
 
开发者ID:coderwjq,项目名称:ZhaZhaShop,代码行数:17,代码来源:ExpandTextView.java

示例4: addData

import android.widget.ImageView; //导入方法依赖的package包/类
public void addData(int rec) {
    if (ly_tool != null) {
        View toolBtnView = inflate(mContext, R.layout.emoticonstoolbar_item, null);
        ImageView iv_icon = (ImageView) toolBtnView.findViewById(R.id.iv_icon);
        iv_icon.setImageResource(rec);
        LinearLayout.LayoutParams imgParams = new LinearLayout.LayoutParams(Utils.dip2px(mContext, mBtnWidth), LayoutParams.MATCH_PARENT);
        iv_icon.setLayoutParams(imgParams);
        ly_tool.addView(toolBtnView);
        final int position = mToolBtnList.size();
        mToolBtnList.add(iv_icon);
        iv_icon.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                if (mItemClickListeners != null && !mItemClickListeners.isEmpty()) {
                    for (OnToolBarItemClickListener listener : mItemClickListeners) {
                        listener.onToolBarItemClick(position);
                    }
                }
            }
        });
    }
}
 
开发者ID:yangchaojiang,项目名称:ChatKeyboard-master,代码行数:23,代码来源:EmoticonsToolBarView.java

示例5: ChatUnreadCell

import android.widget.ImageView; //导入方法依赖的package包/类
public ChatUnreadCell(Context context) {
    super(context);

    FrameLayout frameLayout = new FrameLayout(context);
    //frameLayout.setBackgroundResource(R.drawable.newmsg_divider);
    addView(frameLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 27, Gravity.LEFT | Gravity.TOP, 0, 7, 0, 0));

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.ic_ab_new);
    imageView.setPadding(0, AndroidUtilities.dp(2), 0, 0);
    frameLayout.addView(imageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL, 0, 0, 10, 0));

    textView = new TextView(context);
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setPadding(0, 0, 0, AndroidUtilities.dp(1));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setTextColor(Theme.CHAT_UNREAD_TEXT_COLOR);
    textView.setTypeface(FontManager.instance().getTypeface());
    addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));

    ColorUtils.ColorPresenter c= ChitSettings.currentColorPresenter();
    try {
        c.modifyUnreadBg(frameLayout, textView);
    }catch (Exception e){}

}
 
开发者ID:MLNO,项目名称:airgram,代码行数:27,代码来源:ChatUnreadCell.java

示例6: addTab

import android.widget.ImageView; //导入方法依赖的package包/类
/**
 * add tab
 * @param icon
 */
public void addTab(int icon){
    View tabView = View.inflate(context, R.layout.ease_scroll_tab_item, null);
    ImageView imageView = (ImageView) tabView.findViewById(R.id.iv_icon);
    imageView.setImageResource(icon);
    int tabWidth = 60;
    LinearLayout.LayoutParams imgParams = new LinearLayout.LayoutParams(DensityUtil.dip2px(context, tabWidth), LayoutParams.MATCH_PARENT);
    imageView.setLayoutParams(imgParams);
    tabContainer.addView(tabView);
    tabList.add(imageView);
    final int position = tabList.size() -1;
    imageView.setOnClickListener(new OnClickListener() {
        
        @Override
        public void onClick(View v) {
            if(itemClickListener != null){
                itemClickListener.onItemClick(position);
            }
        }
    });
}
 
开发者ID:Vicent9920,项目名称:FanChat,代码行数:25,代码来源:EaseEmojiconScrollTabBar.java

示例7: setImageViewResource

import android.widget.ImageView; //导入方法依赖的package包/类
/**
 * 通过android:imageUrl可以在xml布局中直接为ImageView设置url地址,这样方便业务中使用第三方库加载网络图片
 *
 * @param imageView xml中ImageView实例
 * @param imgUrl    网络图片地址
 */
@BindingAdapter({"android:imageUrl"})
public static void setImageViewResource(ImageView imageView, String imgUrl) {
    Context context = imageView.getContext();
    //此处通过imgUrl字符串获取资源ID,具体使用根据业务需要
    int resId = context.getResources().getIdentifier(imgUrl, "drawable", context.getPackageName());
    imageView.setImageResource(resId);
}
 
开发者ID:free46000,项目名称:MultiItem,代码行数:14,代码来源:DataBindUtil.java

示例8: initTodayOverview

import android.widget.ImageView; //导入方法依赖的package包/类
private void initTodayOverview(TodayOverview todayOverview) {
    int i = R.drawable.a1j;
    if (todayOverview != null) {
        this.mIvCaloryStatus.setImageResource(todayOverview.calory_status ? R.drawable.a1j :
                R.drawable.a1p);
        this.mIvDietStatus.setImageResource(todayOverview.diet_status ? R.drawable.a1j : R
                .drawable.a1p);
        ImageView imageView = this.mIvNuturitionStatus;
        if (!todayOverview.nuturition_status) {
            i = R.drawable.a1p;
        }
        imageView.setImageResource(i);
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:15,代码来源:TodayAnalysisActivity.java

示例9: Slider

import android.widget.ImageView; //导入方法依赖的package包/类
/**
 * Constructor
 * 
 * @param parent
 *            the container view of this one
 * @param tabId
 *            drawable for the tab
 * @param barId
 *            drawable for the bar
 * @param targetId
 *            drawable for the target
 */
Slider(ViewGroup parent, int iconId, int targetId, int barId, int tabId) {
	// Create tab
	tab = new ImageView(parent.getContext());
	tab.setBackgroundResource(tabId);
	tab.setImageResource(iconId);
	tab.setScaleType(ScaleType.CENTER);
	tab.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

	// Create hint TextView
	text = new TextView(parent.getContext());
	text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
	text.setBackgroundResource(barId);
	if(!parent.isInEditMode()) {
	    text.setTextAppearance(parent.getContext(), R.style.TextAppearance_SlidingTabNormal);
	}
	
	// Create target
	target = new ImageView(parent.getContext());
	target.setImageResource(targetId);
	target.setScaleType(ScaleType.CENTER);
	target.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
	target.setVisibility(View.INVISIBLE);
	
	
	// this needs to be first - relies on painter's algorithm
	parent.addView(target); 
	parent.addView(tab);
	parent.addView(text);
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:42,代码来源:SlidingTab.java

示例10: PageIndicator

import android.widget.ImageView; //导入方法依赖的package包/类
public PageIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PageIndicator);
    normalIndicator = a.getResourceId(R.styleable.PageIndicator_normal_indicator,
            R.drawable.shape_point_white_alpha);
    selectedIndicator = a.getResourceId(R.styleable.PageIndicator_selected_indicator,
            R.drawable.shape_point_black);
    a.recycle();

    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams
            (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    llIndicators = new LinearLayout(context);
    llIndicators.setLayoutParams(params);
    llIndicators.setOrientation(LinearLayout.HORIZONTAL);

    indicator = new ImageView(context);
    FrameLayout.LayoutParams params1 = new FrameLayout.LayoutParams
            (LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    indicator.setLayoutParams(params1);
    indicator.setImageResource(selectedIndicator);//默认使用白色实心点

    this.addView(llIndicators);
    this.addView(indicator);


}
 
开发者ID:BittleDragon,项目名称:MyRepository,代码行数:29,代码来源:PageIndicator.java

示例11: getHeaderView

import android.widget.ImageView; //导入方法依赖的package包/类
private View getHeaderView(int type, View.OnClickListener listener) {
    View view = getLayoutInflater().inflate(R.layout.head_view, (ViewGroup) mRecyclerView.getParent(), false);
    if (type == 1) {
        ImageView imageView = (ImageView) view.findViewById(R.id.iv);
        imageView.setImageResource(R.mipmap.rm_icon);
    }
    view.setOnClickListener(listener);
    return view;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:10,代码来源:HeaderAndFooterUseActivity.java

示例12: onCreateView

import android.widget.ImageView; //导入方法依赖的package包/类
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.view_tutorial, container, false);
    ImageView imageView = view.findViewById(R.id.imageView);
    TextView textView = view.findViewById(R.id.textView);
    imageView.setImageResource(imageID);
    textView.setText(content);
    return view;
}
 
开发者ID:DSM-GRAM,项目名称:Artist,代码行数:11,代码来源:TutorialAdapter.java

示例13: createView

import android.widget.ImageView; //导入方法依赖的package包/类
@Override
public View createView(Context context) {
    LayoutInflater inflater = LayoutInflater.from(context);

    RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.example_toolbar_item, null, false);

    ImageView imageView = new ImageView(context);
    imageView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
    imageView.setImageResource(R.drawable.example_toolbar_separator);

    layout.addView(imageView);

    return layout;
}
 
开发者ID:ABTSoftware,项目名称:SciChart.Android.Examples,代码行数:15,代码来源:SeparatorWidget.java

示例14: getView

import android.widget.ImageView; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // Get the data item for this position
    About about = (About) getItem(position);

    // Check if an existing view is being reused, otherwise inflate the view
    ViewHolder viewHolder;

    // view lookup cache stored in tag
    final View result;

    if (convertView == null) {

        viewHolder = new ViewHolder();

        LayoutInflater inflater = LayoutInflater.from(getContext());
        convertView = inflater.inflate(R.layout.about_item, parent, false);

        viewHolder.title = (TextView) convertView.findViewById(R.id.title_about);
        viewHolder.subTitle = (TextView) convertView.findViewById(R.id.description);

        result=convertView;

        convertView.setTag(viewHolder);
    } else {
        viewHolder = (ViewHolder) convertView.getTag();
        result=convertView;
    }

    Animation animation = AnimationUtils.loadAnimation(mContext,
            (position > lastPosition) ? R.anim.down_from_top : R.anim.down_from_top);
    result.startAnimation(animation);
    lastPosition = position;

    viewHolder.title.setText(about.getTitle());
    viewHolder.subTitle.setText(about.getSubTitle());

    ImageView item_about = (ImageView) convertView.findViewById(R.id.item_about);
    item_about.setImageResource(about.getAboutImage(position));
    // Return the completed view to render on screen
    return convertView;
}
 
开发者ID:fga-gpp-mds,项目名称:2017.1-Trezentos,代码行数:43,代码来源:AboutAdapter.java

示例15: initialize

import android.widget.ImageView; //导入方法依赖的package包/类
private void initialize(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr,
        @StyleRes int defStyleRes) {
    mPreviewView = new SurfaceView(context);
    mPreviewView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    mViewFinderView = new ViewFinderView(context);
    mViewFinderView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    mButtonSize = Math.round(displayMetrics.density * BUTTON_SIZE_DP);
    mAutoFocusButton = new ImageView(context);
    mAutoFocusButton.setLayoutParams(new LayoutParams(mButtonSize, mButtonSize));
    mAutoFocusButton.setScaleType(ImageView.ScaleType.CENTER);
    mAutoFocusButton.setImageResource(R.drawable.ic_code_scanner_auto_focus_on);
    mAutoFocusButton.setOnClickListener(new AutoFocusClickListener());
    mFlashButton = new ImageView(context);
    mFlashButton.setLayoutParams(new LayoutParams(mButtonSize, mButtonSize));
    mFlashButton.setScaleType(ImageView.ScaleType.CENTER);
    mFlashButton.setImageResource(R.drawable.ic_code_scanner_flash_on);
    mFlashButton.setOnClickListener(new FlashClickListener());
    if (attrs == null) {
        mViewFinderView.setSquareFrame(DEFAULT_SQUARE_FRAME);
        mViewFinderView.setMaskColor(DEFAULT_MASK_COLOR);
        mViewFinderView.setFrameColor(DEFAULT_FRAME_COLOR);
        mViewFinderView.setFrameThickness(Math.round(DEFAULT_FRAME_THICKNESS_DP * displayMetrics.density));
        mViewFinderView.setFrameCornersSize(Math.round(DEFAULT_FRAME_CORNER_SIZE_DP * displayMetrics.density));
        mAutoFocusButton.setColorFilter(DEFAULT_AUTO_FOCUS_BUTTON_COLOR);
        mFlashButton.setColorFilter(DEFAULT_FLASH_BUTTON_COLOR);
        mAutoFocusButton.setVisibility(DEFAULT_AUTO_FOCUS_BUTTON_VISIBILITY);
        mFlashButton.setVisibility(DEFAULT_FLASH_BUTTON_VISIBILITY);
    } else {
        TypedArray attributes = null;
        try {
            attributes = context.getTheme()
                    .obtainStyledAttributes(attrs, R.styleable.CodeScannerView, defStyleAttr, defStyleRes);
            mViewFinderView.setSquareFrame(
                    attributes.getBoolean(R.styleable.CodeScannerView_squareFrame, DEFAULT_SQUARE_FRAME));
            mViewFinderView
                    .setMaskColor(attributes.getColor(R.styleable.CodeScannerView_maskColor, DEFAULT_MASK_COLOR));
            mViewFinderView.setFrameColor(
                    attributes.getColor(R.styleable.CodeScannerView_frameColor, DEFAULT_FRAME_COLOR));
            mViewFinderView.setFrameThickness(attributes
                    .getDimensionPixelSize(R.styleable.CodeScannerView_frameThickness,
                            Math.round(DEFAULT_FRAME_THICKNESS_DP * displayMetrics.density)));
            mViewFinderView.setFrameCornersSize(attributes
                    .getDimensionPixelSize(R.styleable.CodeScannerView_frameCornersSize,
                            Math.round(DEFAULT_FRAME_CORNER_SIZE_DP * displayMetrics.density)));
            mAutoFocusButton.setColorFilter(attributes
                    .getColor(R.styleable.CodeScannerView_autoFocusButtonColor, DEFAULT_AUTO_FOCUS_BUTTON_COLOR));
            mFlashButton.setColorFilter(
                    attributes.getColor(R.styleable.CodeScannerView_flashButtonColor, DEFAULT_FLASH_BUTTON_COLOR));
            mAutoFocusButton.setVisibility(attributes.getBoolean(R.styleable.CodeScannerView_autoFocusButtonVisible,
                    DEFAULT_AUTO_FOCUS_BUTTON_VISIBLE) ? VISIBLE : INVISIBLE);
            mFlashButton.setVisibility(attributes
                    .getBoolean(R.styleable.CodeScannerView_flashButtonVisible, DEFAULT_FLASH_BUTTON_VISIBLE) ?
                    VISIBLE : INVISIBLE);
        } finally {
            if (attributes != null) {
                attributes.recycle();
            }
        }
    }
    addView(mPreviewView);
    addView(mViewFinderView);
    addView(mAutoFocusButton);
    addView(mFlashButton);
}
 
开发者ID:yuriy-budiyev,项目名称:code-scanner,代码行数:66,代码来源:CodeScannerView.java


注:本文中的android.widget.ImageView.setImageResource方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。