2015-09-21 4 views
1

Я пытаюсь установить минимальную ширину для пунктов в RecyclerView с GridManagerLayoutУстановка минимальной ширины элемента RecyclerView

Если я ставлю 5 пунктов в строке это выглядит здорово, но когда я ставлю 20 пунктов для каждой строки в размер элемента как 20 dp, но я хочу, чтобы он был как минимум 120 дп. Как я могу это сделать?

GridLayoutManager manager = new GridLayoutManager(ActividadesColectivasPlazasActivity.this, columnas); 


adapter = new PlazasAdapter(ctx, listaPlazas); 

mRecyclerView.setLayoutManager(manager); 
mRecyclerView.setHasFixedSize(true); 

Layout

<HorizontalScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/app_bar"> 

    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent"> 
     <view 
      android:layout_width="wrap_content" 
      android:layout_height="fill_parent" 
      class="android.support.v7.widget.RecyclerView" 
      android:layout_marginTop="10dp" 
      android:minWidth="500dp" 
      android:id="@+id/recycler_view" /> 
    </LinearLayout> 





</HorizontalScrollView> 

Адаптер XML

<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="80dp" 
android:minWidth="120dp" 
android:background="@drawable/fondo_stroke_gris" 
android:orientation="vertical" 
android:gravity="center" 
tools:context="com.psapp_provisport.activity.MenuActivity" > 


<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_marginTop="10dp" 
    android:layout_weight="1" > 

    <ImageView 
     android:id="@+id/imagen" 
     android:layout_width="wrap_content" 
     android:layout_height="match_parent" 
     android:layout_centerHorizontal="true" 
     android:src="@drawable/ic_launcher"/> 

    <ProgressBar 
     android:id="@+id/pb1" 
     style="?android:attr/progressBarStyleLarge" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:visibility="invisible" /> 
</RelativeLayout> 

<TextView 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="5dp" 
    android:layout_marginBottom="5dp" 
    android:gravity="center" 
    android:id="@+id/nombre" /> 

+2

Вы можете использовать что-то вроде этого, чтобы автоматически рассчитать диапазон на основе ширины экрана: http://blog.sqisland.com/2014/12/recyclerview-autofit-grid.html –

ответ

1

Для acomplish это я просто изменить miniumwidth из Recycler View программно с числом столбцов * 300

GridLayoutManager manager = new GridLayoutManager(ActividadesColectivasPlazasActivity.this, columnas); 
mRecyclerView.setMinimumWidth(columnas*300);