有些消息来源告诉array.sort/collections.sort/compare/comparator
和layout_width
是layout_height
的属性。 (https://developer.android.com/reference/android/view/ViewGroup.LayoutParams.html)
但是,我们可以在TextView类的XML代码中使用这些属性。
class LayoutParams
怎么可能呢?
<TextView
android:id = "@+id/text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"/>
是继承class TextView
还是class ViewGroup
?
答案 0 :(得分:0)
我不确定我是否完全理解这个问题,但“wrap_content”和“match_parent”实际上只是指定了整数 “wrap_content”= -2且“match_parent”= -1,以便:
<TextView
android:id = "@+id/text_view"
android:layout_width="-2"
android:layout_height="-2"
android:text="Hello World!"/>
会是同样的事情。这回答了这个问题吗?
答案 1 :(得分:0)
以layout_
开头的查看属性将应用于视图LayoutParams
。可用属性取决于视图的父类型(因为它定义了视图正在使用的LayoutParams
的特定子类)。
答案 2 :(得分:0)
在Android中,每个View都必须声明屏幕上需要多少空间。 您可以在XML中定义它,就像在您显示的代码段中一样,或者通过代码中的LayoutParams定义它。
P.S:
ViewGroup实际上只是一个“常规”视图(它扩展了View类) - 一个专门用于保存子视图的视图。
答案 3 :(得分:0)
通常在绘制方法期间使用android:layout_width
和android:layout_height
,因此当父级(LinearLayout,RelativeLayout ..)想要绘制他的孩子时,这些参数可以作为父母的指导。