android 引导蒙层实现
ringa_lee
ringa_lee 2017-04-18 09:03:54
0
3
2602

页面结构:activity-fragment—recycleView
目标,整个页面蒙层,并在recycleView的第一个item上添加一个高亮提示。
现在我要获取这个item的view,在onResume中使用getLayoutManager.findViewByPosition方法得到的view为空。
我应该何时何地获取该view?

ringa_lee
ringa_lee

ringa_lee

reply all(3)
Ty80

getLayoutManager.findViewByPosition(...) is called at the wrong time

getView().post(new Runnable() {
    View view = getLayoutManager.findViewByPosition(0);
    // TODO ...
});
大家讲道理

Use view tree listening to get the corresponding controls or properties:

//1.开启视图树监听
recycleView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

    @Override
    public void onGlobalLayout() {
        //2.视图绘制完毕,取出第一个item
        View view = recyclerView.getChildAt(0);
        //3.注销监听
        recyclerView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        //4. do something with the first itemview...
    }
});
左手右手慢动作

It is possible to use the view tree monitoring method upstairs. Use getViewTreeObserver().addOnGlobalLayoutListener() to obtain the final width or height of the View, and getViewTreeObserver().addOnDrawListener to monitor the redrawing of the View. This is a common method

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template