现象:
ScrollView嵌套RecyclerView,当我离开当前页面,然后又回来时,RecyclerView就会把它上边的控件都挤出页面,当前的界面显示的是最底部。
ListView的子布局里有CheckBox,CheckBox的点击事件有,但是子布局的点击事件监听不到;
原因:
这都是因为它们的焦点被占用了
解决办法:
ScrollView里面只能放一个ViewGroup,所以一班使用是在里面放一个LinearLayout(或RelativeLayout等),然后在LinearLayout(或RelaticeLayout等)里面添加要滑动的布局,要想解决这个问题可以在LinearLayout(或RelativeLayout等)的布局里添加一行代码:
<ScrollView android:id="@+id/goods_view_sv_scrollView" android:layout_width="match_parent" android:layout_height="match_parent"> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="blocksDescendants"> 在RecyclerView的子布局里同样也是添加这行代码就可以解决这个bug啦。 查看descendatFocusability的解析
新闻热点
疑难解答