getChildAt(int postion)

public View getChildAt(int index)

Returns: the view at the specified position in the group.?or null if the position does not exist within the group

index: the position at which to get the view from( 方法里面的參數就是布局里面層次的索引)

在一個View中調用getChildAt(int index)方法,假如這個View的布局如下:

?在這個自定義View的java代碼中使用getChildAt方法

那 getChildAt(1) 返回的是一個LinearLayout, (2)就是一個include里面的view

代碼如下:

mWapper = (LinearLayout) getChildAt(0);

mMenu = (ViewGroup) getChildAt(1);

mContent = (ViewGroup) getChildAt(1);

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容