动态操作后GridLayoutManager中的java项高度
我有一个RecyclerView和GridLayoutManager,有两列。项目中填充了DiffUtil,到目前为止一切正常。 这些项目由图像(高度始终相同)和文本组成,它们的长度可能不同,因此具有动态高度
GridLayoutManager似乎将行中的每一项都安排为具有相同高度。但一旦它们改变行,它不会重新计算它们->;只要单元当前可见,单元的高度就保持不变
示例:共6项
A | B
C | D
E | F
因此,如果项目E有一个短文本,比如说高度100,项目F有一个长文本,高度500,两个项目的高度都是500
如果项目B被删除,则E将行从3更改为2,但仍然具有500的高度,而项目D可能只有150。E则表示“350太高”。 这会产生一种奇怪的外观,因为在第2行和第3行之间有很多空白
一旦你向后滚动(=这些项目不再可见),一切都会再次正常测量
我怎样才能解决这个问题
谢谢你的帮助
更新:
项目。xml:
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content">
<LinearLayout
安卓:id="@+id/items_folder_item_container"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:clickable="true"
安卓:focusable="true"
安卓:paddingTop="15dp"
安卓:paddingStart="10dp"
安卓:paddingEnd="10dp"
安卓:paddingBottom="15dp"
安卓:background="?安卓:attr/selectableItemBackground"
安卓:orientation="horizontal">
<LinearLayout
安卓:layout_width="0dp"
安卓:layout_height="wrap_content"
安卓:orientation="vertical"
安卓:layout_weight="1">
<RelativeLayout
安卓:layout_width="127dp"
安卓:id="@+id/items_folder_item_folder_container"
安卓:layout_gravity="center_horizontal"
安卓:layout_height="127dp">
<ImageView
安卓:id="@+id/items_folder_item_folder"
安卓:layout_width="127dp"
安卓:layout_height="127dp"
安卓:src="@{folder.homeFolder ? (folder.homeIconType == 1 ? @drawable/ic_ordner_weis : (folder.homeIconType == 2 ? @drawable/ic_navi_bons : @drawable/ic_home_grey_48px)) : @drawable/ic_ordner_weis }"
安卓:tint="@{folder.folderColorCode}"
安卓:contentDescription="@null" />
<ImageView
安卓:layout_width="17dp"
安卓:layout_height="17dp"
安卓:contentDescription="@null"
安卓:layout_alignParentBottom="true"
安卓:layout_marginBottom="30dp"
安卓:layout_marginStart="24dp"
安卓:visibility="@{item.selectionMode ? selectedFolders.contains(item) View.GONE : View.VISIBLE : View.GONE}"
安卓:src="@drawable/ic_item_selection_placeholder" />
<ImageView
安卓:layout_width="27dp"
安卓:layout_height="27dp"
安卓:contentDescription="@null"
安卓:layout_alignParentBottom="true"
安卓:layout_marginBottom="27dp"
安卓:layout_marginStart="22dp"
安卓:visibility="@{selectedFolders.contains(item) == true ? View.VISIBLE : View.GONE}"
安卓:src="@drawable/ic_item_selected" />
</RelativeLayout>
<LinearLayout
安卓:id="@+id/items_folder_item_content"
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_marginEnd="10dp"
安卓:orientation="vertical">
<LinearLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:gravity="center_horizontal"
安卓:orientation="horizontal">
<ImageView
安卓:layout_width="16dp"
安卓:layout_height="16dp"
安卓:layout_marginEnd="9dp"
安卓:layout_gravity="center_vertical"
安卓:src="@{item.item.visibleToContact ? @drawable/ic_shared : @drawable/ic_shared_in_progress}"
安卓:visibility="@{item.item.itemPermitted ? View.VISIBLE : View.GONE}"
安卓:contentDescription="@null" />
<ImageView
安卓:layout_width="16dp"
安卓:layout_height="16dp"
安卓:layout_marginEnd="7dp"
安卓:layout_gravity="center_vertical"
安卓:visibility="@{folder.folderIsFavorite == true ? View.VISIBLE : View.GONE}"
安卓:src="@drawable/ic_favorite_set"
安卓:contentDescription="@null" />
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:gravity="center_horizontal"
style="@style/ItemNameGrid"
安卓:textColor="@{selectedFolders.contains(item) ? @color/gridItemSelectedTextColor : @color/brownGreyText}"
安卓:text="@{folder.folderName}" />
</LinearLayout>
<TextView
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:layout_gravity="center_horizontal"
安卓:visibility="@{folder.homeFolder ? View.GONE : View.VISIBLE}"
style="@style/ItemInfoTextGrid"
安卓:textColor="@{selectedFolders.contains(item) ? @color/gridItemSelectedTextColor : @color/bluishGreyText}"
安卓:text='@{folder.folderItemCount == 1 ? String.format(@string/items_item_element, folder.folderItemCount) : String.format(@string/items_item_elements, folder.folderItemCount) }' />
</LinearLayout>
</LinearLayout>
<RelativeLayout
安卓:id="@+id/items_folder_item_more_container"
安卓:layout_width="37dp"
安卓:clickable="true"
安卓:focusable="true"
安卓:layout_gravity="bottom"
安卓:visibility="@{inChoosingMode ? folder.homeFolder ? View.INVISIBLE : View.VISIBLE : item.selectionMode ? View.INVISIBLE : View.VISIBLE}"
安卓:layout_height="37dp">
<ImageView
安卓:layout_width="27dp"
安卓:layout_height="27dp"
安卓:layout_centerVertical="true"
安卓:layout_centerHorizontal="true"
安卓:background="?selectableItemBackgroundBorderless"
安卓:src="@{inChoosingMode ? @drawable/ic_arrow_right : @drawable/ic_more}"
安卓:contentDescription="@null" />
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
回收视图布局:
<RelativeLayout
xmlns:安卓="http://schemas.安卓.com/apk/res/安卓" 安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:layout_marginTop="20dp"
安卓:background="@color/defaultBackgroundColor"
安卓:id="@+id/items_root">
<安卓x.swiperefreshlayout.widget.SwipeRefreshLayout
安卓:layout_width="match_parent"
安卓:id="@+id/items_refresh_layout"
安卓:layout_height="match_parent">
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent">
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:id="@+id/items_content">
<RelativeLayout
安卓:layout_width="match_parent"
安卓:layout_height="wrap_content"
安卓:layout_marginEnd="22dp"
安卓:layout_marginTop="20dp"
安卓:layout_marginStart="22dp"
安卓:id="@+id/items_topbar">
<com.fm.atmin.controls.sortfilter.sort.SortControl
安卓:id="@+id/items_topbar_sort_control"
安卓:layout_width="wrap_content"
安卓:layout_centerVertical="true"
安卓:layout_height="wrap_content" />
<LinearLayout
安卓:layout_width="wrap_content"
安卓:layout_height="wrap_content"
安卓:orientation="horizontal"
安卓:clickable="true"
安卓:background="?安卓:attr/selectableItemBackground"
安卓:layout_alignParentEnd="true"
安卓:id="@+id/items_view_mode_container"
安卓:focusable="true">
<ImageView
安卓:id="@+id/items_view_mode"
安卓:layout_width="27dp"
安卓:layout_height="27dp"
安卓:src="@drawable/ic_view_module_grid"
/>
</LinearLayout>
</RelativeLayout>
<安卓x.recyclerview.widget.RecyclerView
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:id="@+id/items_recyclerview"
安卓:layout_below="@id/items_topbar"
安卓:layout_marginTop="25dp" />
</RelativeLayout>
<include
layout="@layout/items_no_content"
安卓:layout_width="match_parent"
安卓:layout_height="match_parent"
安卓:visibility="gone"/>
<include
layout="@layout/no_network_layout"
安卓:visibility="gone"/>
</RelativeLayout>
</安卓x.swiperefreshlayout.widget.SwipeRefreshLayout>
共 (0) 个答案