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

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

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

ImageView.<init>介绍

暂无

代码示例

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

ImageView img = new ImageView(this);
img.setImageResource(R.drawable.my_image);

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

if(getIntent().hasExtra("byteArray")) {
  ImageView previewThumbnail = new ImageView(this);
  Bitmap b = BitmapFactory.decodeByteArray(
    getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);        
  previewThumbnail.setImageBitmap(b);
}

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

LinearLayout  layout=new LinearLayout(this);
 layout.setBackgroundResource(R.color.LightOrange);
 TextView  tv=new TextView(this);
 // set the TextView properties like color, size etc
 tv.setTextColor(Color.RED);
 tv.setTextSize(15);        
 tv.setGravity(Gravity.CENTER_VERTICAL);
 // set the text you want to show in  Toast
 tv.setText("My Custom Toast at Bottom of Screen");  
 ImageView   img=new ImageView(this);
 // give the drawble resource for the ImageView
 img.setImageResource(R.drawable.myimage);
// add both the Views TextView and ImageView in layout
 layout.addView(img);
 layout.addView(tv);
 Toast toast=new Toast(this); //context is object of Context write "this" if you are an Activity
 // Set The layout as Toast View
 toast.setView(layout);
  // Position you toast here toast position is 50 dp from bottom you can give any integral value   
  toast.setGravity(Gravity.BOTTOM, 0, 50);
  toast.show();

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

//LinearLayOut Setup
LinearLayout linearLayout= new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);

linearLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));

//ImageView Setup
ImageView imageView = new ImageView(this);

//setting image resource
imageView.setImageResource(R.drawable.play);

//setting image position
imageView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, 
LayoutParams.WRAP_CONTENT));

//adding view to layout
linearLayout.addView(imageView);
//make visible to program
setContentView(linearLayout);

代码示例来源:origin: Ramotion/folding-cell-android

/**
 * Create image view for display selected bitmap
 *
 * @param bitmap bitmap to display in image view
 * @return ImageView with selected bitmap
 */
protected ImageView createImageViewFromBitmap(Bitmap bitmap) {
  ImageView imageView = new ImageView(getContext());
  imageView.setImageBitmap(bitmap);
  imageView.setLayoutParams(new LayoutParams(bitmap.getWidth(), bitmap.getHeight()));
  return imageView;
}

代码示例来源:origin: Ramotion/cardslider-android

@Override
  public View makeView() {
    final ImageView imageView = new ImageView(MainActivity.this);
    imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    final LayoutParams lp = new ImageSwitcher.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    imageView.setLayoutParams(lp);
    return imageView;
  }
}

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

@Test
 public void getDrawableResourceId_shouldWorkWhenTheDrawableWasCreatedFromAResource() throws Exception {

  Resources resources = ApplicationProvider.getApplicationContext().getResources();
  Bitmap bitmap = BitmapFactory.decodeResource(resources, R.drawable.an_image);
  ImageView imageView = new ImageView(ApplicationProvider.getApplicationContext());
  imageView.setImageBitmap(bitmap);

  imageView.setImageResource(R.drawable.an_image);
  assertThat(shadowOf(imageView.getDrawable()).getCreatedFromResId()).isEqualTo(R.drawable.an_image);
 }
}

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

private void useScaledImage() {
  Resources res = getResources();
  BitmapDrawable bd = (BitmapDrawable)res.getDrawable(R.drawable.sun);
  Bitmap b = Bitmap.createScaledBitmap(bd.getBitmap(),
             (int) (bd.getIntrinsicHeight() * 0.7),
             (int) (bd.getIntrinsicWidth() * 0.7),
             false);

  LinearLayout l = new LinearLayout(this);
  ImageView iv = new ImageView(this);

  iv.setImageDrawable(new BitmapDrawable(b));
  iv.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

  l.addView(iv);

  setContentView(l);
}

代码示例来源:origin: GitLqr/LQRWeChat

LinearLayout llLine = new LinearLayout(context);
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, cellHeight);
llPanel.addView(llLine, lp);
  lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, cellHeight);
  lp.weight = 1;
  llLine.addView(llCells[i * lineSize + j], lp);
    llLine.addView(vSep, lp);
ImageView ivLogo = new ImageView(context);
ivLogo.setScaleType(ScaleType.CENTER_INSIDE);
lp = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, logoHeight);

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

@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    final DialogMenuItem item = mMenuItems.get(position);

    LinearLayout ll_item = new LinearLayout(mContext);
    ll_item.setOrientation(LinearLayout.HORIZONTAL);
    ll_item.setGravity(Gravity.CENTER_VERTICAL);

    ImageView iv_item = new ImageView(mContext);
    iv_item.setPadding(0, 0, (int) (15 * mDisplayMetrics.density), 0);
    ll_item.addView(iv_item);

    TextView tv_item = new TextView(mContext);
    tv_item.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
        LinearLayout.LayoutParams.WRAP_CONTENT));
    tv_item.setSingleLine(true);
    tv_item.setTextColor(Color.parseColor("#303030"));
    tv_item.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

    ll_item.addView(tv_item);
    ll_item.setPadding(item.mResId == 0 ? (int) (18 * mDisplayMetrics.density) : (int) (16 * mDisplayMetrics.density), (int) (10 * mDisplayMetrics.density), 0,
        (int) (10 * mDisplayMetrics.density));

    iv_item.setImageResource(item.mResId);
    tv_item.setText(item.mOperName);
    iv_item.setVisibility(item.mResId == 0 ? View.GONE : View.VISIBLE);

    return ll_item;
  }
}

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

//assuming your layout is in a LinearLayout as its root
LinearLayout layout = (LinearLayout)findViewById(R.id.rootlayout);

ImageView image = new ImageView(this);
image.setImageResource(R.drawable.image);

int newHeight = getWindowManager().getDefaultDisplay().getHeight() / 2;
int orgWidth = image.getDrawable().getIntrinsicWidth();
int orgHeight = image.getDrawable().getIntrinsicHeight();

//double check my math, this should be right, though
int newWidth = Math.floor((orgWidth * newHeight) / orgHeight);

//Use RelativeLayout.LayoutParams if your parent is a RelativeLayout
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
  newWidth, newHeight);
image.setLayoutParams(params);
image.setScaleType(ImageView.ScaleType.CENTER_CROP);
layout.addView(image);

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

ImageView img = new ImageView(this);  // or (ImageView) findViewById(R.id.myImageView);
img.setImageResource(R.drawable.my_image);

代码示例来源:origin: Ramotion/paper-onboarding-android

/**
 * @param PaperOnboardingPage new content page to show
 * @return configured view with new content image
 */
protected ImageView createContentIconView(PaperOnboardingPage PaperOnboardingPage) {
  ImageView contentIcon = new ImageView(mAppContext);
  contentIcon.setImageResource(PaperOnboardingPage.getContentIconRes());
  FrameLayout.LayoutParams iconLP = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
  iconLP.gravity = Gravity.CENTER;
  contentIcon.setLayoutParams(iconLP);
  return contentIcon;
}

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

if(getIntent().hasExtra("byteArray")) {
ImageView previewThumbnail = new ImageView(this);
Bitmap b = BitmapFactory.decodeByteArray(
  getIntent().getByteArrayExtra("byteArray"),0,getIntent().getByteArrayExtra("byteArray").length);        
previewThumbnail.setImageBitmap(b);
}

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

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.icon);
 RelativeLayout layout = (RelativeLayout) findViewById(R.id.layout);
 RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
     RelativeLayout.LayoutParams.FILL_PARENT, 
     RelativeLayout.LayoutParams.WRAP_CONTENT);
 ImageView imageView = new ImageView(this);
 imageView.setLayoutParams(params);
 imageView.setImageBitmap(bitmap);
 layout.setGravity(Gravity.CENTER_VERTICAL | Gravity.TOP);
 layout.addView(imageView);

代码示例来源:origin: Ramotion/expanding-collection-android

public View makeView() {
    ImageView myView = new ImageView(context);
    myView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    myView.setLayoutParams(new FrameLayout.LayoutParams(bgImageWidth, FrameLayout.LayoutParams.MATCH_PARENT));
    myView.setTranslationX(-bgImageGap);
    return myView;
  }
});

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

imagesPathList.add(imagesPath[i]);
yourbitmap = BitmapFactory.decodeFile(imagesPath[i]);
ImageView imageView = new ImageView(this);
imageView.setImageBitmap(yourbitmap);
imageView.setAdjustViewBounds(true);
lnrImages.addView(imageView);

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

ImageView newImageView=new ImageView();

//set the ImageView image with one of the following:
newImageView.setImageBitmap(bm);
newImageView.setImageDrawable(drawable);
newImageView.setImageResource(resId);

//add the new ImageView to your layout
imageScrollLayout.addView(newImageView);

相关文章

ImageView类方法