Android开发经验笔记

getChildAt(int postion)

2015-01-09  本文已影响106人  陈利健

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);

上一篇 下一篇

猜你喜欢

热点阅读