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

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

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

ImageView.setId介绍

暂无

代码示例

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

RelativeLayout rl = (RelativeLayout) findViewById(R.id.my_relative_layout);
ImageView iv;
RelativeLayout.LayoutParams params;

int yellow_iv_id = 123; // Some arbitrary ID value.

iv = new ImageView(this);
iv.setId(yellow_iv_id);
iv.setBackgroundColor(Color.YELLOW);
params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 50;
params.topMargin = 60;
rl.addView(iv, params);

iv = new ImageView(this);
iv.setBackgroundColor(Color.RED);
params = new RelativeLayout.LayoutParams(30, 40);
params.leftMargin = 80;
params.topMargin = 90;

// This line defines how params.leftMargin and params.topMargin are interpreted.
// In this case, "<80,90>" means <80,90> to the right of the yellow ImageView.
params.addRule(RelativeLayout.RIGHT_OF, yellow_iv_id);

rl.addView(iv, params);

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

LinearLayout layout = (LinearLayout) findViewById(R.id.linear);
 for (int i = 0; i < 10; i++) {
   ImageView imageView = new ImageView(this);
   imageView.setId(i);
   imageView.setPadding(2, 2, 2, 2);
   imageView.setImageBitmap(BitmapFactory.decodeResource(
       getResources(), R.drawable.ic_launcher));
   imageView.setScaleType(ScaleType.FIT_XY);
   layout.addView(imageView);
 }

代码示例来源:origin: lygttpod/SuperTextView

/**
 * 初始化左边ImageView
 * 主要是为了便于使用第三方图片框架获取网络图片使用
 */
private void initLeftImageView() {
  leftImageView = new ImageView(mContext);
  leftIVParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
  leftIVParams.addRule(ALIGN_PARENT_LEFT, TRUE);
  leftIVParams.addRule(RelativeLayout.CENTER_VERTICAL, TRUE);
  leftIVParams.setMargins(mLeftImageViewMarginLeft, 0, 0, 0);
  leftImageView.setScaleType(ImageView.ScaleType.CENTER);
  leftImageView.setId(R.id.cLeftImageViewId);
  leftImageView.setLayoutParams(leftIVParams);
  if (mLeft_IV_drawable != null) {
    leftImageView.setImageDrawable(mLeft_IV_drawable);
  }
  addView(leftImageView);
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

private ImageView createImageView(int position, final boolean isMultiImage) {
  String url = imagesList.get(position);
  ImageView imageView = new ColorFilterImageView(getContext());
  if(isMultiImage){
    imageView.setScaleType(ScaleType.CENTER_CROP);
    imageView.setLayoutParams(position % MAX_PER_ROW_COUNT == 0 ?moreParaColumnFirst : morePara);
  }else {
    imageView.setAdjustViewBounds(true);
    imageView.setScaleType(ScaleType.CENTER_CROP);
    imageView.setMaxHeight(pxOneMaxWandH);
    imageView.setLayoutParams(onePicPara);
  }
  imageView.setTag(R.string.zone_img_position,position);
  imageView.setId(url.hashCode());
  imageView.setOnClickListener(mImageViewOnClickListener);
  ImageLoaderUtils.display(getContext(), imageView, ImageUtil.getImageUrl(url));
  return imageView;
}

代码示例来源:origin: Naoki2015/CircleDemo

imageView.setId(photoInfo.url.hashCode());
imageView.setOnClickListener(new ImageOnClickListener(position));
imageView.setBackgroundColor(getResources().getColor(R.color.im_font_color_text_hint));

代码示例来源:origin: Bearded-Hen/Android-Bootstrap

closeButton.setId(generateViewUniqueId());
closeButton.setId(View.generateViewId());

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

ImageView refreshImg = new ImageView(activity);
ImageView settingsImg = new ImageView(activity); 

   refreshImg.setId(R.id.refresh);
   settingsImg .setId(R.id.settings);

代码示例来源:origin: multidots/android-app-common-tasks

provider.setId(i);
provider.setImageResource(authProviderLogos[i]);
provider.setPadding(5, 5, 5, 5);

代码示例来源:origin: multidots/android-app-common-tasks

provider.setId(i);
provider.setImageResource(authProviderLogos[i]);
provider.setPadding(5, 5, 5, 5);

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

// Give more sensible names to ID's
int IMAGEVIEW_ID = 0;
int TEXTVIEW1_ID = 1;
int TEXTVIEW2_ID = 2;
int TEXTVIEW3_ID = 3;

imageView.setId(IMAGEVIEW_ID);
textView1.setId(TEXTVIEW1_ID);
textView2.setId(TEXTVIEW2_ID);
textView3.setId(TEXTVIEW3_ID);

...
// somewhere later
ImageView imageView = (ImageView) convertView.findViewById(IMAGEVIEW_ID);

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

for (int i = 0; i < listImages.size(); i++) {
   final ImageView image = listImages.get(i);
   image.setImageResource(R.drawable.have_fun);
   image.setId(i);
 }

代码示例来源:origin: wasdennnoch/AndroidN-ify

protected View createIcon() {
  final ImageView icon = new ImageView(mContext);
  icon.setId(android.R.id.icon);
  icon.setScaleType(ScaleType.CENTER_INSIDE);
  return icon;
}

代码示例来源:origin: dsolonenko/financisto

public ListBuilder withClearButtonId(int buttonId, OnClickListener listener) {
  ImageView plusImageView = v.findViewById(R.id.bMinus);
  plusImageView.setId(buttonId);
  plusImageView.setOnClickListener(listener);
  return this;
}

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

View linearLayout =  findViewById(R.id.your_main_xml);
     ImageView newImage=new ImageView(this);
     newImage.setId(5);
     newImage.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
     ((LinearLayout) linearLayout).addView(newImage);
     newImage.setImageBitmap(bitmap);

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

int[] images = {R.drawable.image_01, R.drawable.image_02, R.drawable.image_03, R.drawable.image_04, R.drawable.image_05};

for (int i = 0; i < images.length; i++) {
  ImageView imageView = new ImageView(this);
  imageView.setId(i);
  imageView.setPadding(2, 2, 2, 2);
  imageView.setLayoutParams(layoutParams);
  imageView.setImageBitmap(BitmapFactory.decodeResource(
        getResources(), images[i]));
  imageView.setScaleType(ImageView.ScaleType.FIT_XY);
  mainHorizLinLayout.addView(imageView);
}

代码示例来源:origin: JmStefanAndroid/PVCloudGroupn

private ImageView createImageView(String thumbUrl,int position,LayoutParams params){

    ImageView imageView = new ImageView(getContext());
    imageView.setId(thumbUrl.hashCode());//指定id

    imageView.setLayoutParams(params);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//                    imageView.setImageResource(thumbUrl);


    imageView.setTag(position);
    imageView.setOnClickListener(ImageViewOnClickListener);

    return  imageView;

  }

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

setContentView(R.layout.your_layout);
FrameLayout baseFrame = (FrameLayout) findViewById(R.id.baseFrame);

ImageView imageView = new ImageView(this);
imageView.setWidth(/*As per your need*/);
imageView.setHeight(/*As per your need*/);
imageView.setId(/*Any unique positive Number*/ R.ids.imageView1); <= Required to access this view later
/*Set the layout parameters such as layout_gravity as well.*/
baseFrame.addView(imageView);

代码示例来源:origin: mylhyl/Android-CircleDialog

private void init() {
    LayoutParams layoutParams = new LayoutParams(LayoutParams.MATCH_PARENT,
        LayoutParams.WRAP_CONTENT);
    mImageView = new ImageView(getContext());
    mImageView.setId(android.R.id.icon);
    mImageView.setImageResource(mAdParams.imageResId);
    mImageView.setAdjustViewBounds(true);
    addView(mImageView, layoutParams);
  }
}

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

for(int i=0;i<totalGroups;i++)
{
  ImageView img;
  TextView tv;
  Button b;

  ... // set other properties of above components

  img.setId(i);
  tv.setId(i);
  b.setId(i);

  ... //handle all events on these components here only

  ... //add all components to your main layout
}

代码示例来源:origin: ribot/easy-adapter

@SuppressWarnings("ResourceType") //Because of warning when setting a hardcoded ID into the view
private static LinearLayout createTestLinearLayout() {
  LinearLayout linearLayout = new LinearLayout(RuntimeEnvironment.application);
  TextView textView = new TextView(RuntimeEnvironment.application);
  textView.setId(TEXT_VIEW_ID);
  linearLayout.addView(textView);
  ImageView imageView = new ImageView(RuntimeEnvironment.application);
  imageView.setId(IMAGE_VIEW_ID);
  linearLayout.addView(imageView);
  return linearLayout;
}

相关文章

ImageView类方法