首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    LayoutParams 简单理解[通俗易懂]

    大家好,又见面了,我是你们的朋友全栈君。 简单说说 自己对 android LayoutParams的理解吧。 public static class ViewGroup.LayoutParams extends Object java.lang.Object ↳ android.view.ViewGroup.LayoutParams //继承关系 以下说明摘自官方文档E文好的可以看看 Class Overview LayoutParams are used by views to tell their parents how they want to be laid out. See ViewGroup Layout Attributes for a list of all child view attributes that this class supports. The base LayoutParams class just describes how big the view wants to be for both width and height. For each dimension, it can specify one of: FILL_PARENT (renamed MATCH_PARENT in API Level 8 and higher), which means that the view wants to be as big as its parent (minus padding) WRAP_CONTENT, which means that the view wants to be just big enough to enclose its content (plus padding) an exact number There are subclasses of LayoutParams for different subclasses of ViewGroup. For example, AbsoluteLayout has its own subclass of LayoutParams which adds an X and Y value. E文不好看不懂 但是觉得写得啰嗦了 其实这个LayoutParams类是用于child view(子视图) 向 parent view(父视图)传达自己的意愿的一个东西(孩子想变成什么样向其父亲说明)其实子视图父视图可以简单理解成 一个LinearLayout 和 这个LinearLayout里边一个 TextView 的关系 TextView 就算LinearLayout的子视图 child view 。需要注意的是LayoutParams只是ViewGroup的一个内部类 这里边这个也就是ViewGroup里边这个LayoutParams类是 base class 基类 实际上每个不同的ViewGroup都有自己的LayoutParams子类 比如LinearLayout 也有自己的 LayoutParams 大家打开源码看几眼就知道了 myeclipse 怎么查看源码 请看 http://byandby.iteye.com/blog/814277 下边来个例子

    03
    领券