【发布时间】:2019-08-29 13:58:54
【问题描述】:
我尝试按位置获取 childView。我写了类似这样的代码
private void showDirectDebitShadow(int pos, String message) {
boolean allowScale = false;
if (pos > 0 && isRecyclerScrollable()) {
templateList.getRecyclerView().post(() -> layoutManager.scrollToPosition(pos));
}
if (pos < layoutManager.findLastVisibleItemPosition()) {
allowScale = false;
} else {
allowScale = true;
}
new Handler().postDelayed(() -> {
templateList.getRecyclerView().post(() -> {
View childView = layoutManager.findViewByPosition(pos);
if (childView != null) {
childView.postDelayed(() -> {
SwipeMenuLayout swipeMenuLayout = childView.findViewById(R.id.SwipeMenuLayout);
View directDebitIcon = childView.findViewById(R.id.direct_debit_icon);
if (swipeMenuLayout != null && directDebitIcon != null) {
swipeMenuLayout.smoothExpand();
new Handler().postDelayed(() -> showCaseView(message, directDebitIcon, getActivity(), swipeMenuLayout), 400);
}
},500);
}
});
}, isRecyclerScrollable() ? 500 : 100);
}
我调试了它,我的子视图不为空,但我可以从 childView 获得另一个视图(SwipeMenuLayout 和 directDebitIcon) 谁能告诉我这段代码有什么问题?
【问题讨论】:
标签: android android-recyclerview android-linearlayout