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

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

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

ImageView.setLayoutParams介绍

暂无

代码示例

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

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 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: 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: 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: stackoverflow.com

public View getView(int position, View convertView, ViewGroup parent) {
  ImageView i = new ImageView(context);
  // Move cursor to current position
  cursor.moveToPosition(position);
  // Get the current value for the requested column
  int imageID = cursor.getInt(columnIndex);
  // obtain the image URI
  Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
  String url = uri.toString();
  // Set the content of the image based on the image URI
  int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
  Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
          originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
  i.setImageBitmap(b);
  i.setLayoutParams(new Gallery.LayoutParams(150, 100));
  i.setScaleType(ImageView.ScaleType.FIT_XY);
  i.setBackgroundResource(mGalleryItemBackground);
  return i;
}

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

/**
 * Create image view for display back side of flip view
 *
 * @param height height for view
 * @return ImageView with selected height and default background color
 */
protected ImageView createBackSideView(int height) {
  ImageView imageView = new ImageView(getContext());
  imageView.setBackgroundColor(mBackSideColor);
  imageView.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, height));
  return imageView;
}

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

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: Rukey7/MvpApp

layoutParams.width = getResources().getDisplayMetrics().widthPixels * 7 / 10;
layoutParams.height = getResources().getDisplayMetrics().heightPixels * 7 / 10;
photo.setLayoutParams(layoutParams);
if (mBitmap != null) {
  photo.setImageBitmap(mBitmap);

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

public View getView(int arg0, View arg1, ViewGroup arg2) {

  if(arg1!=null)
  {
    ImageView imv = new ImageView(cont);
    imv.setLayoutParams(new GridView.LayoutParams(40,40));
    imv.setScaleType(ScaleType.CENTER_CROP);
    imv.setPadding(0,0,0,0);

    arg1 = imv;
  }
  arg1.setTag(arg0);
  return arg1;
}

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

@Override
  public void onGlobalLayout() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      iv.getViewTreeObserver().removeOnGlobalLayoutListener(this);
    } else {
      iv.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    }
    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) iv.getLayoutParams();
    params.height = params.width;
    iv.setLayoutParams(params);
    iv.setScaleType(ImageView.ScaleType.CENTER_CROP);
  }
});

代码示例来源:origin: medyo/Fancybuttons

/**
 * Text Icon resource view
 *
 * @return : ImageView
 */
private ImageView setupIconView() {
  if (mIconResource != null) {
    ImageView iconView = new ImageView(mContext);
    iconView.setImageDrawable(mIconResource);
    iconView.setPadding(mIconPaddingLeft, mIconPaddingTop, mIconPaddingRight, mIconPaddingBottom);
    LayoutParams iconViewParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    if (mTextView != null) {
      if (mIconPosition == POSITION_TOP || mIconPosition == POSITION_BOTTOM)
        iconViewParams.gravity = Gravity.CENTER;
      else
        iconViewParams.gravity = Gravity.START;
      iconViewParams.rightMargin = 10;
      iconViewParams.leftMargin = 10;
    } else {
      iconViewParams.gravity = Gravity.CENTER_VERTICAL;
    }
    iconView.setLayoutParams(iconViewParams);
    return iconView;
  }
  return null;
}

代码示例来源:origin: wangdan/AisenWeiBo

imgCover.setLayoutParams(lp);
imgCover.setPadding(0, 0, 0, layDetail.getHeight());

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

ImageView i = new ImageView(this);
i.setImageResource(mFams.get(position).imageId);
i.setScaleType(ImageView.ScaleType.FIT_CENTER);
final int w = (int) (36 * getResources().getDisplayMetrics().density + 0.5f);
i.setLayoutParams(new GridView.LayoutParams(w * 2, w * 2));
return i;

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

// create a new ImageView for each item referenced by the Adapter
 public View getView(int position, View convertView, ViewGroup parent) {
   ImageView imageView;
   if (convertView == null) {  
     //Calculation of ImageView Size - density independent.
     //maybe you should do this calculation not exactly in this method but put is somewhere else.
     Resources r = Resources.getSystem();
     float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 60, r.getDisplayMetrics());
     imageView = new ImageView(mContext);
     imageView.setLayoutParams(new GridView.LayoutParams((int)px, (int)px));
     imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
     //imageView.setPadding(8, 8, 8, 8);
     imageView.setBackgroundColor(Color.BLUE);
   } else {
     imageView = (ImageView) convertView;
   }
   imageView.setImageResource(mThumbIds[position]);
   return imageView;
 }

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

public View getView(int position, View convertView, ViewGroup parent) {
  ImageView i = new ImageView(context);
  // Move cursor to current position
  cursor.moveToPosition(position);
  // Get the current value for the requested column
  int imageID = cursor.getInt(columnIndex);
  // obtain the image URI
  Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
  String url = uri.toString();
  // Set the content of the image based on the image URI
  int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
  Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
          originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
  i.setImageBitmap(b);
  i.setLayoutParams(new Gallery.LayoutParams(150, 100));
  i.setScaleType(ImageView.ScaleType.FIT_XY);
  i.setBackgroundResource(mGalleryItemBackground);
  return i;
}

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

Resources res = getResources();
ScaleDrawable sd = (ScaleDrawable) res.getDrawable(R.drawable.logo2);
Drawable d = sd.getDrawable();

d.setLevel(1);

ImageView iv = new ImageView(this);
iv.setImageDrawable(sd);
iv.setAdjustViewBounds(true); 
iv.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

setContentView(iv);

相关文章

ImageView类方法