ImageView imageView = new ImageView(mcontext);
LayoutParams layoutParams = new LayoutParams(150,130);
layoutParams.leftMargin=20;
// layoutParams.leftMargin
imageView.setLayoutParams(layoutParams); //添加view 到layout
imageView.setScaleType(ScaleType.FIT_XY);
imageView.setBackgroundResource(R.drawable.shape_border_img);
ImageLoader.getInstance().displayImage(productslist.get(i).getPimg(), imageView);
viewHolder.product_img_lin.addView(imageView); // layout加上imageview

第二种 :

// 创建LinearLayout
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setLayoutParams(new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
// Creates a new ImageView
ImageView imageView = new ImageView(this);
// Sets the bitmap for the ImageView from an icon bit map (defined
// elsewhere)
imageView.setImageResource(R.drawable.play);
// 或者通过名字来获取,int id = getResources().getIdentifier("gameover",
// "drawable", getPackageName());
int id = getResources().getIdentifier("play", "drawable",
getPackageName());
imageView.setImageResource(id);
// setting image position
imageView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Sets the tag
imageView.setTag(IMAGEVIEW_TAG);
// adding view to layout
linearLayout.addView(imageView);
// make visible to program
setContentView(linearLayout);

new LayoutParams 使用的更多相关文章

  1. WindowManager.LayoutParams 札记

    WindowManager.LayoutParams wlp = new WindowManager.LayoutParams(width, height, WindowManager.LayoutP ...

  2. [Android] 转-LayoutInflater丢失View的LayoutParams

    原文地址:http://lmbj.net/blog/layoutinflater-and-layoutparams/ View view = inflater.inflate(R.layout.ite ...

  3. 安卓冷知识:LayoutParams

    安卓的布局有很多种,每种都有对应的LayoutParams类,那么它们之间到底是什么关系? 为什么在编写Layout的XML文件时,有的layout_前缀属性有用有的没有用? 一句话道出LayoutP ...

  4. 通过inflate获取布局,设置layoutparams无效

    给ll——addtiem当设置layoutparams无效时,试着修改上一个布局的属性

  5. ListView的LayoutParams设置

    // Temp is the root view that was found in the xml final View temp = createViewFromTag(root, name, a ...

  6. Android LayoutParams简介

    LayoutParams是子控件控制自己在父控件中布局的一个类. 不同布局都有相对的LayoutParams,最简单的LinearLayout.LayoutParams类可以设置布局的宽高. 我在写一 ...

  7. 简单研究Android View绘制二 LayoutParams

    2015-07-28 17:23:20 本篇是关于LayoutParams相关 ViewGroup.LayoutParams文档解释如下: LayoutParams are used by views ...

  8. RelativeLayout.LayoutParams.addRule()方法

    1.应用场景 在使用RelativeLayout布局的时候,通常在载入布局之前在相关的XML文件中进行静态设置即可.但是,在有些情况下,我们需要动态的设置布局 的属性,在不同条件下设置不同的布局排列方 ...

  9. android中的layoutparams参数使用的简单总结

    定义: 我们可以在Android的framework中的ViewGroup类里找到定义的类: public static class LayoutParams{...} 此类有如下注释: Layout ...

  10. LayoutParams使用

    LayoutParams继承于Android.View.ViewGroup.LayoutParams.       LayoutParams相当于一个Layout的信息包,它封装了Layout的位置. ...

随机推荐

  1. Data Structure Array: Find if there is a subarray with 0 sum

    http://www.geeksforgeeks.org/find-if-there-is-a-subarray-with-0-sum/ #include <iostream> #incl ...

  2. FreeMarker使用后台枚举

    //页面使用枚举全路径访问 model.addAttribute("enums", BeansWrapper.getDefaultInstance().getEnumModels( ...

  3. 新手用的git配置命令

    新手用的git配置命令 /**第一次链接远程仓库 本地已有项目需要上传码云 */ //1.配置码云用户名 git config --global user.name "昵称" // ...

  4. table-cell笔记

    display:table-cell可将元素设为类似于table的td一样的布局,在垂直居中.两行自适应布局.等高布局下有很高的利用价值 详见: http://www.zhangxinxu.com/w ...

  5. 20145229吴姗珊《JAVA程序设计》第一周学习总结

    教材学习内容总结 第一章 JAVA 平台概论 1.JAVA不仅仅是一门程序设计语言,还是标准规范 2.1995年5月23日被公认为JAVA的诞生日 3.J2SE包含了JDK和JAVA程序语言 4.三大 ...

  6. 大话设计模式--命令模式 Command -- C++实现实例

    1. 命令模式: 将请求封装为一个对象,从而使你可以用不同的请求对客户进行参数化,对请求排队或记录请求日志,以及支持可撤销的操作. 命令模式有点: a. 较容易的设计一个命令队列 b. 在需要的的情况 ...

  7. strnpy函数

    函数原型: char * strncpy ( char * destination, const char * source, size_t num ); 功能:从字符串source中复制 num个字 ...

  8. hadoop_学习_00_资源帖

    一.精品 1.虚无境的博客 随笔分类 - hadoop 二.参考资料 1.大数据学习之路(持续更新中...) 2.Hadoop安装教程_单机/伪分布式配置_CentOS6.4/Hadoop2.6.0 ...

  9. 如何更好的理解js中的this,分享2段有意思的代码

    关于js中this的浅析,大家可以点击[彻底理解js中this的指向,不必硬背]这篇博客了解. 今天遇到2段比较有意思的代码. ----------------第一段----------------- ...

  10. jQuery 事件 - one() 方法

    jQuery 事件参考手册 实例 当点击 p 元素时,增加该元素的文本大小: $("p").one("click",function(){ $(this).an ...