设置 RecyclerView 项目的最小宽度
Setting minimum width of a RecyclerView item
我正在尝试为带有 GridManagerLayout 的 RecyclerView 的项目设置最小宽度
如果我每行放置 5 个项目,它看起来不错,但是当我每行放置 20 个项目时,项目的大小大约为 20 dp,但我希望它至少为 120 dp,我该怎么做?
GridLayoutManager manager = new GridLayoutManager(ActividadesColectivasPlazasActivity.this, columnas);
adapter = new PlazasAdapter(ctx, listaPlazas);
mRecyclerView.setLayoutManager(manager);
mRecyclerView.setHasFixedSize(true);
布局
<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" />
为了完成它,我只是用列数*300
以编程方式更改 Recycler View 的线宽
GridLayoutManager manager = new GridLayoutManager(ActividadesColectivasPlazasActivity.this, columnas);
mRecyclerView.setMinimumWidth(columnas*300);
我正在尝试为带有 GridManagerLayout 的 RecyclerView 的项目设置最小宽度
如果我每行放置 5 个项目,它看起来不错,但是当我每行放置 20 个项目时,项目的大小大约为 20 dp,但我希望它至少为 120 dp,我该怎么做?
GridLayoutManager manager = new GridLayoutManager(ActividadesColectivasPlazasActivity.this, columnas);
adapter = new PlazasAdapter(ctx, listaPlazas);
mRecyclerView.setLayoutManager(manager);
mRecyclerView.setHasFixedSize(true);
布局
<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" />
为了完成它,我只是用列数*300
以编程方式更改 Recycler View 的线宽GridLayoutManager manager = new GridLayoutManager(ActividadesColectivasPlazasActivity.this, columnas);
mRecyclerView.setMinimumWidth(columnas*300);