android.widget.ImageView类的使用及代码示例

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

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

ImageView介绍

暂无

代码示例

代码示例来源: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: stackoverflow.com

public View getView(int position, View convertView, ViewGroup parent) {
  View v;
  if (convertView == null) {  // if it's not recycled, initialize some attributes
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(     Context.LAYOUT_INFLATER_SERVICE );
    v = inflater.inflate(R.layout.gridview_item_layout, parent, false);
  } else {
    v = (View) convertView;
  }
  TextView text = (TextView)v.findViewById(R.id.grid_item_text);
  text.setText(mTextIds[position]);
  ImageView image = (ImageView)v.findViewById(R.id.grid_item_image);
  image.setImageDrawable(mThumbIds[position]);
  return v;
}

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

@Override
public int onFinish(@NonNull RefreshLayout layout, boolean success) {
  mProgressDrawable.stop();//停止动画
  mProgressView.setVisibility(GONE);//隐藏动画
  if (success){
    mHeaderText.setText("刷新完成");
  } else {
    mHeaderText.setText("刷新失败");
  }
  return 500;//延迟500毫秒之后再弹回
}

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

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

代码示例来源:origin: google/ExoPlayer

private void hideArtwork() {
 if (artworkView != null) {
  artworkView.setImageResource(android.R.color.transparent); // Clears any bitmap reference.
  artworkView.setVisibility(INVISIBLE);
 }
}

代码示例来源:origin: Yalantis/Side-Menu.Android

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
             Bundle savedInstanceState) {
  View rootView = inflater.inflate(R.layout.fragment_main, container, false);
  mImageView = (ImageView) rootView.findViewById(R.id.image_content);
  mImageView.setClickable(true);
  mImageView.setFocusable(true);
  mImageView.setImageResource(res);
  return rootView;
}

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

btnSelect.setOnClickListener(new OnClickListener() {
      Intent i = new Intent();
      i.putExtra("data", selectImages);
      setResult(Activity.RESULT_OK, i);
  protected void onPostExecute(Bitmap result) {
    super.onPostExecute(result);
    iv.setImageBitmap(result);
  if (convertView == null) {
    holder = new ViewHolder();
    convertView = mInflater.inflate(R.layout.custom_gallery_item, null);
    holder.imgThumb = (ImageView) convertView.findViewById(R.id.imgThumb);
    holder.chkImage = (CheckBox) convertView.findViewById(R.id.chkImage);
    convertView.setTag(holder);
  } else {
    holder = (ViewHolder) convertView.getTag();

代码示例来源:origin: android-hacker/VirtualXposed

@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;
    if (convertView == null) {
      convertView = mLayoutInflater.inflate(R.layout.choose_account_row, null);
      holder = new ViewHolder();
      holder.text = (TextView) convertView.findViewById(R.id.account_row_text);
      holder.icon = (ImageView) convertView.findViewById(R.id.account_row_icon);
      convertView.setTag(holder);
    } else {
      holder = (ViewHolder) convertView.getTag();
    }
    holder.text.setText(mInfos.get(position).name);
    holder.icon.setImageDrawable(mInfos.get(position).drawable);
    return convertView;
  }
}

代码示例来源:origin: pockethub/PocketHub

private void setUpHeaderView() {
  ImageView userImage;
  TextView userRealName;
  TextView userName;
  View headerView = navigationView.getHeaderView(0);
  userImage = headerView.findViewById(R.id.user_picture);
  ImageView notificationIcon = headerView.findViewById(R.id.iv_notification);
  userRealName = headerView.findViewById(R.id.user_real_name);
  userName = headerView.findViewById(R.id.user_name);
  notificationIcon.setOnClickListener(v ->
      startActivity(new Intent(MainActivity.this, NotificationActivity.class)));
  avatars.bind(userImage, org);
  userName.setText(org.login());
  String name = org.name();
  if (name != null) {
    userRealName.setText(org.name());
  } else {
    userRealName.setVisibility(View.GONE);
  }
}

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

private void bindView(int position, View row) {
  TextView label=(TextView)row.findViewById(R.id.label);
  
  label.setText(getItem(position).loadLabel(pm));
  
  ImageView icon=(ImageView)row.findViewById(R.id.icon);
  
  icon.setImageDrawable(getItem(position).loadIcon(pm));
 }
}

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

captureBtn.setOnClickListener(this);
if (v.getId() == R.id.capture_btn) {
  try {
  if (requestCode == CAMERA_CAPTURE) {
    picUri = data.getData();
    performCrop();
    Bundle extras = data.getExtras();
    picView.setImageBitmap(thePic);
  Intent cropIntent = new Intent("com.android.camera.action.CROP");
  cropIntent.setDataAndType(picUri, "image/*");

代码示例来源:origin: HotBitmapGG/bilibili-android-client

private void createHeadView() {
    View headView = LayoutInflater.from(this).inflate(R.layout.layout_vip_game_head_view, mRecycle, false);
    ImageView mVipGameImage = (ImageView) headView.findViewById(R.id.vip_game_image);
    Glide.with(GameCentreActivity.this).load(mVipGameInfoData.getImgPath())
        .diskCacheStrategy(DiskCacheStrategy.ALL).into(mVipGameImage);
    mVipGameImage.setOnClickListener(v -> BrowserActivity.launch(GameCentreActivity.this,
        mVipGameInfoData.getLink(), "年度大会员游戏礼包专区"));
    mHeaderViewRecyclerAdapter.addHeaderView(headView);
  }
}

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

@Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
   super.onActivityResult(requestCode, resultCode, data);
   if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
     Uri selectedImage = data.getData();
     String[] filePathColumn = { MediaStore.Images.Media.DATA };
     Cursor cursor = getContentResolver().query(selectedImage,filePathColumn, null, null, null);
     cursor.moveToFirst();
     int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
     String picturePath = cursor.getString(columnIndex);
     cursor.close();
     ImageView imageView = (ImageView) findViewById(R.id.imgView);
     imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));
   }
 }

代码示例来源: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: ankidroid/Anki-Android

@Override
public void createUI(Context context, LinearLayout layout) {
  mImagePreview = new ImageView(mActivity);
      android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
  setPreviewImage(mField.getImagePath(), getMaxImageSize());
  mImagePreview.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
  mImagePreview.setAdjustViewBounds(true);
  mImagePreview.setMaxHeight((int) Math.round(height * 0.4));
  mImagePreview.setMaxWidth((int) Math.round(width * 0.6));
  mBtnCamera.setText(gtxt(R.string.multimedia_editor_image_field_editing_photo));
  mBtnCamera.setOnClickListener(v -> {
    Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    File image;
    File storageDir;
          image);
      cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
      if (cameraIntent.resolveActivity(context.getPackageManager()) != null) {
        mActivity.startActivityForResultWithoutAnimation(cameraIntent, ACTIVITY_TAKE_PICTURE);

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

btnAddPhots = (Button)findViewById(R.id.btnAddPhots);
btnSaveImages = (Button)findViewById(R.id.btnSaveImages);
btnAddPhots.setOnClickListener(this);
btnSaveImages.setOnClickListener(this);
switch (view.getId()) {
  case R.id.btnAddPhots:
    Intent intent = new Intent(MainActivity.this,CustomPhotoGalleryActivity.class);
    startActivityForResult(intent,PICK_IMAGE_MULTIPLE);
    break;
  if(requestCode == PICK_IMAGE_MULTIPLE){
    imagesPathList = new ArrayList<String>();
    String[] imagesPath = data.getStringExtra("data").split("\\|");
    try{
      lnrImages.removeAllViews();
      imagesPathList.add(imagesPath[i]);
      yourbitmap = BitmapFactory.decodeFile(imagesPath[i]);
      ImageView imageView = new ImageView(this);
      imageView.setImageBitmap(yourbitmap);
      imageView.setAdjustViewBounds(true);
      lnrImages.addView(imageView);

代码示例来源:origin: HotBitmapGG/bilibili-android-client

public void onBindFooterViewHolder(RecyclerView.ViewHolder holder) {
  final FootViewHolder footViewHolder = (FootViewHolder) holder;
  footViewHolder.mDynamic.setText(String.valueOf(mRandom.nextInt(200)) + "条新动态,点这里刷新");
  footViewHolder.mRefreshBtn.setOnClickListener(v -> footViewHolder.mRefreshBtn
      .animate()
      .rotation(360)
      .setInterpolator(new LinearInterpolator())
      .setDuration(1000).start());
  footViewHolder.mRecommendRefresh.setOnClickListener(v -> footViewHolder.mRecommendRefresh
      .animate()
      .rotation(360)
      .setInterpolator(new LinearInterpolator())
      .setDuration(1000).start());
  footViewHolder.mBangumiIndexBtn.setOnClickListener(v -> mContext.startActivity(
      new Intent(mContext, BangumiIndexActivity.class)));
  footViewHolder.mBangumiTimelineBtn.setOnClickListener(v -> mContext.startActivity(
      new Intent(mContext, BangumiScheduleActivity.class)));
  switch (type) {
    case TYPE_RECOMMENDED:
      footViewHolder.mMoreBtn.setVisibility(View.GONE);
      footViewHolder.mRefreshLayout.setVisibility(View.GONE);
      footViewHolder.mBangumiLayout.setVisibility(View.GONE);
      break;
    case TYPE_BANGUMI:
      footViewHolder.mMoreBtn.setVisibility(View.GONE);
      footViewHolder.mRefreshLayout.setVisibility(View.GONE);
      footViewHolder.mRecommendRefreshLayout.setVisibility(View.GONE);

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

Intent intent = new Intent();
mImageView = (ImageView) findViewById(R.id.iv_photo);
button.setOnClickListener(new View.OnClickListener() {
  @Override
  public void onClick(View v) {
  mImageCaptureUri = data.getData();
  Log.i("TAG",
      "After Crop mImageCaptureUri " + mImageCaptureUri.getPath());
  Bundle extras = data.getExtras();
    mImageView.setImageBitmap(bm);
Cursor cursor = managedQuery(contentUri, proj, null, null, null);
int column_index = cursor
    .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);

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

Intent intent = new Intent();
      intent.setType("image/*");
      intent.setAction(Intent.ACTION_GET_CONTENT);
      startActivityForResult(Intent.createChooser(intent,
          "Select Picture"), SELECT_PICTURE);
    selectedImagePath = getPath(selectedImageUri);
    Bitmap bitmap = BitmapFactory.decodeFile(selectedImagePath);
    imageView.setImageBitmap(bitmap);
      Bitmap image = BitmapFactory.decodeFileDescriptor(fileDescriptor);
      parcelFileDescriptor.close();
      imageView.setImageBitmap(image);
if( cursor != null ){
  int column_index = cursor
  .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
  cursor.moveToFirst();
  return cursor.getString(column_index);

代码示例来源:origin: mikepenz/Android-Iconics

@NonNull
  @Override
  @SuppressLint("ViewHolder")
  public View getView(int position, View convertView, @NonNull ViewGroup parent) {
    View v = mInflater.inflate(R.layout.row_icon_array, parent, false);
    ImageView icon = v.findViewById(android.R.id.icon);
    icon.setImageDrawable(getItem(position));
    return v;
  }
}

相关文章

ImageView类方法