티스토리 뷰



문제


RecyclerView 를 이용할 때, 

List 의 스크롤 말고.. List 전체를 스크롤 없이 보여주고 싶을때가 있다.

(내가 스크롤뷰안에 리사이클러 뷰를 넣어 따로 구현하는 경우)


이 경우 아래의 Layout 일 것이다.


<ScrollView>

<!-- Any other view -->


<RecyclerView

android:layout_width="match_parent"

android:layout_height="wrap_contents" />

</ScrollView>



위 처럼 구현한 후, 내가 기대했던 동작은...


RecyclerView 의 높이가 wrap_contents 니까.. 

RecyclerView 의 아이템들이 채워지는 만큼 길이가 늘어날거고, 모든 아이템들이 화면에 다 노출된 상태일 것이다.


나는 상위 View 인 ScrollView 로 스크롤 할 수 있겠지?


그러나 ScrollView 안에 RecyclerView 도 또 Scroll 을 가져 이중스크롤이 되었다.


왜..???






왜 ?


왜 일까?

(정확하진 않다. 추측일뿐.. Debugger 를 돌려보자)

아마도 onMeasure() 가 RecyclerView 의 아이템을 채워넣는 작업보다 더 먼저 실행될거니까,

안드로이드가 판단해서 1 row 만큼의 wrap_contents 를 먼저 잡는게 아닐까? 





검색


해당 이슈에대해 검색해보면 아래와 같은 내용만 있다.


https://stackoverflow.com/questions/27475178/how-do-i-make-wrap-content-work-on-a-recyclerview


요는.. RecyclerView 가 23.2.1 버전부터 해당 이슈가 해결되어 

그냥 wrap_contents 를 써도 된다는것..


하지만, 나는 android.support.v7 이 26인데도 안됐다..

다른방안이 필요하다.





해결


아래와 같이 layout 을 다시 구성하여 해결했다.



<ScrollView>

<!-- Any other view -->


<LinearLayout

android:layout_width="wrap_contents"

android:layout_hegith="wrap_contents"

>

<RecyclerView

android:layout_width="match_parent"

android:layout_height="match_parent" />

</LinearLayout >

</ScrollView>



이게 무슨 조화인지는 모르겠지만, 

부모레이아웃을 하나 더 잡고, wrap, wrap 을 먹인후, 

recyclerview 에는 match, match 로 하면, Recycler View의 아이템들이 모두 나온다.




공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/04   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30
글 보관함