拥有一个带有 GridLayoutManager 的 RecyclerView。每行负责显示三个项目。预期的视图是,连同每个项目,都应该被完整的边框覆盖,没有额外的粗体(4 边等宽)。回收站视图的代码。无论我尝试过什么方法,屏幕的相应 UI 也都附加了。
mHomeRecyclerView = findViewById(R.id.home_screen_recycler_view);
mHomeAdapter = new HomeScreenAdapter(this, mHomeScreenItem);
// to provide scrolling functionality to parent
mHomeRecyclerView.setNestedScrollingEnabled(false);
mHomeRecyclerView.setHasFixedSize(true);
GridLayoutManager layoutManager = new GridLayoutManager(this,3);
mHomeRecyclerView.setLayoutManager(layoutManager);
mHomeRecyclerView.setAdapter(mHomeAdapter);
适配器类的 onCreateViewHolder()
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int):
RecyclerView.ViewHolder {
mLayoutInflater = LayoutInflater.from(mContext)
return HomeItemViewHolder(mLayoutInflater.inflate
(R.layout.layout_home_child_item, parent, false))
}
layout_home_child_item.xml code is below
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/child_item_parent"
android:layout_width="match_parent"
android:layout_height="@dimen/one_not_seven_dp"
android:padding="@dimen/image_select_tag_layout_padding"
android:background="@drawable/shape_sub_category"
android:clickable="true"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/child_item_image"
android:layout_width="@dimen/each_item_dimen"
android:layout_height="@dimen/each_item_dimen" />
<TextView
android:id="@+id/child_item_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/image_icon_in_margin"
android:textSize="@dimen/small_text_size"
android:textColor="@color/result_received_icon_color"
android:maxLines="1"
android:ellipsize="end"
android:gravity="center" />
</LinearLayout>
shape_sub_category.xml 如下所示
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimaryDark" />
<corners android:radius="@dimen/search_card_margin" />
</shape>
</item>
<item android:id="@android:id/background">
<shape android:shape="rectangle">
<stroke
android:width="@dimen/item_background_border_width"
android:color="@color/grid_border_clr" />
<solid android:color="@android:color/transparent" />
</shape>
</item>
但预期的用户界面如下(全覆盖边框,厚度相同)
提前致谢