android.widget.ImageView.setImageResource()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(457)

本文整理了Java中android.widget.ImageView.setImageResource()方法的一些代码示例,展示了ImageView.setImageResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ImageView.setImageResource()方法的具体详情如下:
包路径:android.widget.ImageView
类名称:ImageView
方法名:setImageResource

ImageView.setImageResource介绍

暂无

代码示例

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
  public void displayImage(Context context, Object path, ImageView imageView) {
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    imageView.setImageResource((Integer)path);
  }
}

代码示例来源:origin: facebook/facebook-android-sdk

public void setContentIndex(int index) {
    title.setText(RpsGameUtils.STRINGS_TITLES[index]);
    image.setImageResource(RpsGameUtils.DRAWABLES_HUMAN[index]);
  }
}

代码示例来源:origin: stackoverflow.com

AlertDialog.Builder builder;
AlertDialog alertDialog;

Context mContext = getApplicationContext();
LayoutInflater inflater = (LayoutInflater)
    mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
View layout = inflater.inflate(R.layout.custom_dialog,
    (ViewGroup) findViewById(R.id.layout_root));

TextView text = (TextView) layout.findViewById(R.id.text);
text.setText("Hello, this is a custom dialog!");
ImageView image = (ImageView) layout.findViewById(R.id.image);
image.setImageResource(R.drawable.android);

builder = new AlertDialog.Builder(mContext);
builder.setView(layout);
alertDialog = builder.create();

代码示例来源:origin: googlesamples/google-services

@Override
public View onCreateView(LayoutInflater inflater,
             ViewGroup container,
             Bundle savedInstanceState) {
 View view = inflater.inflate(R.layout.fragment_main, container, false);
 ImageView imageView = (ImageView) view.findViewById(R.id.imageView);
 imageView.setImageResource(resId);
 return view;
}

代码示例来源:origin: TeamNewPipe/NewPipe

private View addItemView(final String title, @DrawableRes final int icon, ViewGroup container) {
  final View itemRoot = View.inflate(getContext(), R.layout.subscription_import_export_item, null);
  final TextView titleView = itemRoot.findViewById(android.R.id.text1);
  final ImageView iconView = itemRoot.findViewById(android.R.id.icon1);
  titleView.setText(title);
  iconView.setImageResource(icon);
  container.addView(itemRoot);
  return itemRoot;
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
  final ViewHolder holder;
  if (convertView == null) {
    holder = new ViewHolder();
    convertView = inflater.inflate(R.layout.list_video_simple_mode2, null);
    holder.videoContainer = (FrameLayout) convertView.findViewById(R.id.list_item_container);
    holder.playerBtn = (ImageView) convertView.findViewById(R.id.list_item_btn);
    holder.imageView = new ImageView(context);
    convertView.setTag(holder);
  } else {
    holder = (ViewHolder) convertView.getTag();
  }
  //增加封面
  holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
  holder.imageView.setImageResource(R.mipmap.xxx1);
  smallVideoHelper.addVideoPlayer(position, holder.imageView, TAG, holder.videoContainer, holder.playerBtn);
  holder.playerBtn.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
      notifyDataSetChanged();
      smallVideoHelper.setPlayPositionAndTag(position, TAG);
      final String url = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
      gsySmallVideoHelperBuilder.setVideoTitle("title " + position)
          .setUrl(url);
      smallVideoHelper.startPlay();
    }
  });
  return convertView;
}

代码示例来源:origin: H07000223/FlycoTabLayout

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.setText(tv_tab_title.getText().toString().toUpperCase());
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,
  iv_tab_icon.setLayoutParams(lp);
} else {
  iv_tab_icon.setVisibility(View.GONE);

代码示例来源:origin: vinc3m1/RoundedImageView

@Override
 public View getView(int position, View convertView, ViewGroup parent) {
  ViewGroup view;
  if (convertView == null) {
   view = (ViewGroup) mInflater.inflate(R.layout.rounded_item, parent, false);
  } else {
   view = (ViewGroup) convertView;
  }
  ColorItem item = getItem(position);
  ((ImageView) view.findViewById(R.id.imageView1)).setImageResource(item.mResId);
  ((ImageView) view.findViewById(R.id.imageView1)).setScaleType(item.mScaleType);
  ((TextView) view.findViewById(R.id.textView1)).setText(item.mLine1);
  ((TextView) view.findViewById(R.id.textView2)).setText(item.mLine2);
  ((TextView) view.findViewById(R.id.textView3)).setText(item.mScaleType.toString());
  return view;
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
public View getView(int position, View convertView, ViewGroup parent) {
 if (getItemViewType(position) == 0) {
  return(getHeaderView(position, convertView, parent));
 }
 View row=convertView;
 if (row == null) {
  row=getLayoutInflater().inflate(R.layout.row, parent, false);
 }
 ViewHolder holder=(ViewHolder)row.getTag();
 if (holder == null) {
  holder=new ViewHolder(row);
  row.setTag(holder);
 }
 String word=(String)getItem(position);
 if (word.length() > 4) {
  holder.icon.setImageResource(R.drawable.delete);
 }
 else {
  holder.icon.setImageResource(R.drawable.ok);
 }
 holder.label.setText(word);
 holder.size.setText(String.format(getString(R.string.size_template),
                  word.length()));
 return(row);
}

代码示例来源:origin: TommyLemon/APIJSON

@SuppressLint("InflateParams")
@Override
public View getRightMenu(Activity activity) {
  if (rightMenu == null) {
    rightMenu = (ImageView) LayoutInflater.from(activity).inflate(R.layout.top_right_iv, null);
    rightMenu.setImageResource(R.drawable.search);
    rightMenu.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        onDragBottom(true);
      }
    });
  }
  return rightMenu;
}

代码示例来源:origin: H07000223/FlycoTabLayout

private void updateTabSelection(int position) {
  for (int i = 0; i < mTabCount; ++i) {
    View tabView = mTabsContainer.getChildAt(i);
    final boolean isSelect = i == position;
    TextView tab_title = (TextView) tabView.findViewById(R.id.tv_tab_title);
    tab_title.setTextColor(isSelect ? mTextSelectColor : mTextUnselectColor);
    ImageView iv_tab_icon = (ImageView) tabView.findViewById(R.id.iv_tab_icon);
    CustomTabEntity tabEntity = mTabEntitys.get(i);
    iv_tab_icon.setImageResource(isSelect ? tabEntity.getTabSelectedIcon() : tabEntity.getTabUnselectedIcon());
    if (mTextBold == TEXT_BOLD_WHEN_SELECT) {
      tab_title.getPaint().setFakeBoldText(isSelect);
    }
  }
}

代码示例来源:origin: stackoverflow.com

public class FullScreenImage extends Activity
{
 protected void onCreate(Bundle savedInstanceState) {
  setContentView(R.layout.full_image);
  Intent intent = getIntent();
  long imageId = intent.getExtras().get(thisClassName.class.getName());
  ImageView imageView = (ImageView)v.findViewById(R.id.fullImage);

  imageView.setLayoutParams( new ViewGroup.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));

      imageView.setImageResource(imageId);
      imageView.setScaleType(ImageView.ScaleType.FIT_XY);

  }
 }

代码示例来源:origin: k9mail/k-9

private void setCryptoProviderIcon(Drawable openPgpApiProviderIcon, View view) {
  ImageView cryptoProviderIcon = view.findViewById(R.id.crypto_error_icon);
  if (openPgpApiProviderIcon != null) {
    cryptoProviderIcon.setImageDrawable(openPgpApiProviderIcon);
  } else {
    cryptoProviderIcon.setImageResource(R.drawable.status_lock_error);
    cryptoProviderIcon.setColorFilter(ThemeUtils.getStyledColor(getContext(), R.attr.openpgp_red));
  }
}

代码示例来源:origin: stackoverflow.com

overlappingImage.setScaleType(ImageView.ScaleType.FIT_XY);
restoreTableLayout();
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(cellWidth, cellHeight);
overlappingImage.setLayoutParams(params);
overlappingImage.setImageResource(R.drawable.horizontal_cat);
container.addView(overlappingImage);
restoreTableLayout();
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(cellWidth*4, cellHeight);
overlappingImage.setLayoutParams(params);
overlappingImage.setImageResource(R.drawable.horizontal_cat);
container.addView(overlappingImage);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(cellWidth*3, cellHeight*2);
params.setMargins(cellWidth*2, cellHeight*2, 0 ,0);
overlappingImage.setLayoutParams(params);
overlappingImage.setImageResource(R.drawable.vertical_cat);
container.addView(overlappingImage);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(cellWidth*2, cellHeight*2);
overlappingImage.setLayoutParams(params);
overlappingImage.setImageResource(R.drawable.horizontal_cat);
container.addView(overlappingImage);

代码示例来源:origin: stackoverflow.com

int id = getResources().getIdentifier("gameover", "drawable", getPackageName());
ImageView imageView = new ImageView(this);
LinearLayout.LayoutParams vp = 
  new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
          LayoutParams.WRAP_CONTENT);
imageView.setLayoutParams(vp);        
imageView.setImageResource(id);        
someLinearLayout.addView(imageView);

代码示例来源:origin: stackoverflow.com

public View getView(int position, View convertView, ViewGroup parent){
   // TODO Auto-generated method stub
   View v;
   if(convertView==null)
   {
     LayoutInflater li = getLayoutInflater();
     v = li.inflate(R.layout.icontext, null);
   }else{
     v = convertView;
   }
   TextView tv = (TextView)v.findViewById(R.id.icon_text);
   tv.setText(providers[position]);
   ImageView iv = (ImageView)v.findViewById(R.id.icon_image);
   iv.setImageResource(R.drawable.icon);
   return v;
 }

代码示例来源:origin: liaoinstan/SpringView

@Override
public View getView(LayoutInflater inflater, ViewGroup viewGroup) {
  View view = inflater.inflate(R.layout.meituan_header, viewGroup, true);
  header_img = (ImageView) view.findViewById(R.id.meituan_header_img);
  if (pullAnimSrcs != null && pullAnimSrcs.length > 0)
    header_img.setImageResource(pullAnimSrcs[0]);
  return view;
}

代码示例来源:origin: commonsguy/cw-omnibus

@Override
 public View getView(int position, View convertView,
           ViewGroup parent) {
  View row=super.getView(position, convertView, parent);
  ImageView icon=(ImageView)row.findViewById(R.id.icon);
   
  if (items[position].length()>4) {
   icon.setImageResource(R.drawable.delete);
  }
  else {
   icon.setImageResource(R.drawable.ok);
  }
  
  TextView size=(TextView)row.findViewById(R.id.size);
  
  size.setText(String.format(getString(R.string.size_template), items[position].length()));
  
  return(row);
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

void bindModel(String item) {
  label.setText(item);
  size.setText(String.format(template, item.length()));
  if (item.length()>4) {
   icon.setImageResource(R.drawable.delete);
  }
  else {
   icon.setImageResource(R.drawable.ok);
  }
 }
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

if (convertView == null) {
  holder = new ViewHolder();
  convertView = inflater.inflate(R.layout.list_video_item, null);
  holder.videoContainer = (FrameLayout) convertView.findViewById(R.id.list_item_container);
  holder.playerBtn = (ImageView) convertView.findViewById(R.id.list_item_btn);
  holder.imageView = new ImageView(context);
  convertView.setTag(holder);
holder.imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
holder.imageView.setImageResource(R.mipmap.xxx1);
smallVideoHelper.addVideoPlayer(position, holder.imageView, TAG, holder.videoContainer, holder.playerBtn);
holder.playerBtn.setOnClickListener(new View.OnClickListener() {

相关文章

ImageView类方法