LayoutParams是什么

中文翻译过来就是“布局参数”。
LayoutParams是Layout提供给其中的Children使用的,他其实就是告诉布局(Parent)控件(Children)想要多宽,想要多高,看一下官方文档。

1.LayoutParams are used by views to tell their parents how they want to be laid out.
– LayoutParams是View用来告诉它的父控件如何放置自己的。

2.The base LayoutParams class just describes how big the view wants to be for both width and height.
– 基类LayoutParams(也就是ViewGroup.LayoutParams)仅仅描述了这个View想要的宽度和高度。

3.There are subclasses of LayoutParams for different subclasses of ViewGroup.
– 不同ViewGroup的继承类对应着不同的ViewGroup.LayoutParams的子类。

文档第二点:基类LayoutParams也就是(ViewGroup.LayoutParams)所能使用的参数只有两种

//第一种
ViewGroup.LayoutParams.MATCH_PARENT
//第二种
ViewGroup.LayoutParams.WRAP_CONTENT

文档第三点:这里用2张继承图解释一下。

简单使用

举例TextView

LinearLayout parent = (LinearLayout)findViewById(R.id.ly_parent);
TextView textView = new TextView(this);
textView.setText("举例");
textView.setTextColor(Color.BLUE);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 50);
parent.addView(textView,lp);

https://blog.csdn.net/yisizhu/article/details/51582622#t1

LayoutParams相关推荐

  1. Android 中文 API 文档 (45) —— AbsoluteLayout.LayoutParams

    前言 本章内容是 android.widget.AbsoluteLayout.LayoutParams,版本为Android 2.2 r1,翻译来自"绵白糖",再次感谢" ...

  2. WindowManager.LayoutParams各种flag含义

    本文实际上就是翻译了官方文档的flag部分,以便使用的时候对照. flags变量设置的值的各种意义//---------------1--------------------------------- ...

  3. WindowManager.LayoutParams类22

    引用:http://www.eoeandroid.com/forum.php?mod=viewthread&tid=84893 WindowManager.LayoutParams 是 Win ...

  4. Android中setLayoutParams要用父控件的LayoutParams

    这几天做程序想明白了一个问题,在此做一下记录. ActionBarCustomView customview = new ActionBarCustomView(context); ActionBar ...

  5. new LayoutParams 使用

    ImageView imageView = new ImageView(mcontext); LayoutParams layoutParams = new LayoutParams(150,130) ...

  6. java.lang.ClassCastException: android.widget.LinearLayout$LayoutParams

    最近,在android中用代码动态改变某种布局(组件)的高度时,会遇到如题所示的类转换异常.上网查了一下,如下所示: These supply parameters to the parent of ...

  7. 【Android】动态UI : LayoutParams.addRule(...) LayoutParams.addRule(..., ...)

    LayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); LayoutParams.addRule(RelativeLayout.ABOVE, ...

  8. ViewGroup.LayoutParams

    LayoutParams are used by views to tell their parents how they want to be laid out. (LayoutPrarms 用于表 ...

  9. 关于LayoutParams

    每一个布局均有一个叫LayoutParams的内部类,如: LinearLayout.LayoutParams  RelativeLayout.LayoutParams  AbsoluteLayout ...

  10. AbsListView.LayoutParams

    AbsListView.LayoutParams lp = new AbsListView.LayoutParams(-1, -2); 创建一个布局(LayoutParams)的实例 lp. AbsL ...

最新文章

  1. iOS 用自签名证书实现 HTTPS 请求的原理实例讲解
  2. 《Adobe Illustrator CC 2014中文版经典教程(彩色版)》—第1课0.15节创建剪切蒙版...
  3. 【树莓派 Raspberry-Pi 】系统安装及一些必要的配置
  4. 中国自研数据库拿下世界第一,背后这十年都经历了什么?
  5. fedora如何删除某个包且不删除依赖它的相关包
  6. newsinglethreadexecutor使用场景_Java线程池的四种用法与使用场景
  7. 惨遭打脸:字节某部门竟然有这么多测试
  8. STL 中的容器们(四)
  9. 发一个招聘软件开发人员的帖子
  10. VS2008内嵌水晶报表翻页BUG修正方法
  11. 684.冗余连接(力扣leetcode) 博主可答疑该问题
  12. html动态添加删除文本框,DOM动态添加与删除元素
  13. OpManager 实时网络监控
  14. 启用和禁用excel 中的加载项
  15. 金蝶报表制作_金蝶财务软件报表制作
  16. tp5ajax轮询,ajax轮询查询状态并输出提示音 TP5+jquery+ajax声音提示功能
  17. vue多张图片实现TV端长图浏览组件
  18. 请各位大咖指点一下备考全国通信技术职业水平考试(初级)的考试经验
  19. LTE空中接口(Uu接口)、RRC信令
  20. mw310r无线路由器怎么设置虚拟服务器,如何设置水星MW310R路由器静态IP地址上网...

热门文章

  1. h5 微信头像图片获取模糊问题
  2. 解决:consumer: Cannot connect to amqp://admin:**@127.0.0.1:5672//: [Errno 111] Connection refused.
  3. 对人工智能常见的误解有哪些_关于AI的道德和偏见的4种误解
  4. 2007年北京市职工年平均工资达39867元
  5. 遨游浏览器主页被hao123劫持解决方法
  6. Python网络爬虫数据采集实战:同花顺动态网页爬取
  7. ks(洛伦兹曲线)指标理解
  8. 国内Android游戏推荐,2月中国安卓游戏收入榜Top20:腾讯八款游戏上榜
  9. JavaScript定时器的各种案例
  10. php 如何判断文件、文件夹/目录是否存在(is_file与file_exists的区别、效率)