activity的oncreate方法执行结束之后走此流程
measure(测量)___layout(设置确认位置)___draw(画)
所以确定位置一定要等到layout后才能确定,可以调用视图树的回调方法来监听,次数用的控件是 iv_redpoint
//监听layout(确认位置)结束的事件,位置确定好了以后再确定小圆点之间的间距iv_redpoint.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {//系统底层可以需要多次调这个方法,而我们只需要用一次就可以了,然后取消掉监听就好了
//加载完layout后的回调事件
iv_redpoint.getViewTreeObserver().removeOnGlobalLayoutListener(this);//需要删除的那个监听
int left1= ll_container.getChildAt(0).getLeft();//在ll_container容器中获取第一个小圆点的位置,在获取左边距
int left2 = ll_container.getChildAt(1).getLeft();//在ll_container容器中获取第二个小圆点的位置,在获取左边距
mPointdis = left2-left1;//两个圆点之间的距离
}
});//获取视图树