2

GridLayoutAdapter와 함께 RecyclerView를 사용하고 있습니다. 항목을 가로 또는 세로로 가운데에 맞출 수 있습니까? RecyclerView GridLayoutAdapter - 항목 가운데 맞추기 방법

내 항목 레이아웃 : http://oi61.tinypic.com/34pjmtc.jpg

원하는 레이아웃과 같아야합니다 : wrap_content에 RecyclerView 설정 http://oi62.tinypic.com/7e2t.jpg

이 작동하지 않습니다, 그것은 여전히 ​​무료로 사용

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:gravity="center" 
       android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/item_photo_image_view" 
     android:layout_width="@dimen/custom_photo_item_size" 
     android:layout_height="@dimen/custom_photo_item_size" 
     android:background="@drawable/custom_image_background" 
     tools:src="@drawable/gallery_list_cars"/> 

</LinearLayout> 

사실은 다음과 같습니다 공간. RecyclerView 내에서 자식 중력을 설정하려면 LayoutManager 책임이 있어야한다고 생각합니다.

+1

이 답변에 대한 답변을 얻으실 수 있습니까? – MidasLefko

+0

아니요. RecyclerView 너비를 하드 코딩하고 컨테이너에서 가로로 가운데에 배치했습니다. – Ralf

답변

2

당신은 이미 줄을했다 :

android:gravity="center" 

을 그 라인으로 당신은 이미 ImageView 수평 및 수직 센터. 당신은 단지 그들 중 하나가 예를 들어 사용하려는 경우

:

android:gravity="center_horizontal" 

내가 정확히 문제가 무엇인지 모르는, 우리가 알지도 못하는 값에 선언

android:layout_width="@dimen/custom_photo_item_size" 

귀하의 dimensions.xml ...

귀하의 전체 Item을 중앙에두고 싶다면 다음을 신고해야합니다 :

android:layout_gravity="Center" 

하지만 당신은 단지 GridView-Cell 하나의 레이아웃을 가지고 당신이 선언이 이해가되지 않는 당신의 품목의 rootView 그래서 당신을 위해 단지 정보가

android:width="match_parent" 
android:height="match_parent" 

로서

)

더 나은 지원을 원한다면 더 많은 정보를 제공하십시오. 어쨌든 도움이 되길 바랍니다.

관련 문제