現象:
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的解析
新聞熱點
疑難解答