gpt4 book ai didi

android - RecyclerView 中的项目越来越小

转载 作者:行者123 更新时间:2023-11-29 15:01:22 24 4
gpt4 key购买 nike

我将 RecyclerView 与 StaggeredGridLayoutManager 和 tabLayout 一起使用我使用 tabLayout 来刷新 RecyclerView 但问题是什么时候每次我刷新时,RecyclerView 中的项目越来越小两张图片清楚地说明了情况第一张照片:

enter image description here

第二张图:

enter image description here

       gaggeredGridLayoutManager = new StaggeredGridLayoutManager(3, 1);
mAdapter= new RecycleRowItemAdapter(list2);
mAdapter.setContext(getContext());
recyclermat.setLayoutManager(gaggeredGridLayoutManager);
recyclermat.setItemAnimator(new DefaultItemAnimator());
int spacingInPixels = getResources().getDimensionPixelSize(R.dimen.photos_list_spacing);
recyclermat.addItemDecoration(new SpacesItemDecoration(spacingInPixels));
recyclermat.setAdapter(mAdapter);

这是我的布局:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">


<RelativeLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"

android:background="@color/gold">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="4">

<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button"
android:text="Filter"
android:textColor="@android:color/white"
android:textSize="12sp" />

<AutoCompleteTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="Enter Search Word"
android:textColor="@android:color/white"
android:textSize="12sp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@drawable/button"
android:text="Invite"
android:textColor="@android:color/white"
android:textSize="12sp" />

</LinearLayout>


</RelativeLayout>


<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
app:tabBackground="@android:color/black"
android:background="@android:color/white"
app:tabMode="scrollable"
app:tabSelectedTextColor="@color/gold"
app:tabTextColor="@android:color/white" />



<android.support.v7.widget.RecyclerView
android:id="@+id/mainrecycle"
android:layout_width="match_parent"
android:layout_height="match_parent"

android:layout_below="@+id/toolbar">

</android.support.v7.widget.RecyclerView>



</LinearLayout>

行项目:

    <LinearLayout
android:id="@+id/mainBord"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/row_item_border"
android:orientation="vertical">

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:adjustViewBounds="true"
android:src="@drawable/icon"
/>


<LinearLayout
android:id="@+id/buttonsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingBottom="2dp"
android:orientation="horizontal">

<TextView
android:id="@+id/priceedt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="5dp"
android:gravity="center"
android:layout_weight="1"
android:textSize="15dp"
android:text="6$"
android:textStyle="bold"/>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="1">
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="@drawable/blank_heart"
android:id="@+id/like"
android:adjustViewBounds="true"
android:layout_weight="1"/>
</LinearLayout>

</LinearLayout>

</LinearLayout>
</android.support.v7.widget.CardView>

有什么想法吗?提前致谢

最佳答案

问题出在项目装饰器上。

recyclermat.addItemDecoration(new SpacesItemDecoration(spacingInPixels));

仅在您初始化 recyclerview 时第一次设置它。

关于android - RecyclerView 中的项目越来越小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45038350/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com