【问题标题】:XML/android: How to make white underline for RecyclerView Item? [duplicate]XML/android:如何为 RecyclerView 项目制作白色下划线? [复制]
【发布时间】:2019-12-06 16:13:42
【问题描述】:

我需要在我的每个回收站视图项目下(从左到右角)画一条小白线,不是针对该项目中的任何特定元素,而是针对整个项目。 (这样用户更容易看到这个特定项目中有哪些元素,以及另一个项目从哪里开始)

这是我的项目布局:

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="@dimen/_5sdp"
    app:cardCornerRadius="0dp"
    app:cardElevation="0dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorPrimaryDark">

        <TextView
            android:id="@+id/nameView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Mike"
            android:textColor="@color/colorAccent"
            android:textSize="@dimen/_21sdp" />

        <ImageView
            android:id="@+id/image_delete"
            android:layout_width="@dimen/_27sdp"
            android:layout_height="@dimen/_27sdp"
            android:layout_alignParentEnd="true"
            android:layout_alignParentRight="true"
            android:layout_marginEnd="0dp"
            android:layout_marginRight="0dp"
            android:layout_marginBottom="@dimen/_4sdp"
            android:background="@drawable/ic_delete" />
    </RelativeLayout>

</androidx.cardview.widget.CardView>

【问题讨论】:

    标签: android xml android-recyclerview view


    【解决方案1】:

    对于你item_layout.xml你可以使用View属性:

     <View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/whiteColor" />
    

    或直接使用recyclerview

    DividerItemDecoration dividerItemDecoration = new DividerItemDecoration(recyclerView.getContext(),layoutManager.getOrientation());
    recyclerView.addItemDecoration(dividerItemDecoration);
    

    【讨论】:

      【解决方案2】:

      只需在项目适配器的末尾添加一个视图:

      <View
       android:layout_width="match_parent"
       android:layout_height="1dp"
       android:background="#FFFFFF"/>
      

      【讨论】:

        【解决方案3】:

        在你的情况下 1) CardView 中进入RelativeLayout 或LinearLayout

         <RelativeLayout> 
                   <androidx.cardview.widget.CardView>
                    //your other view
                   </androidx.cardview.widget.CardView>
         </RelativeLayou> 
        

        然后

        2) 在 Cardview 的结束标签下方添加视图 (下划线)

        <View
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/c"
                android:background="@color/white"
                />
        

          <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_below="@+id/c"
                android:background="@color/white"
                />
        

           <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:layout_below="@+id/c"
                    android:background="@color/white"
                    />
        

        【讨论】:

          猜你喜欢
          • 2021-07-11
          • 1970-01-01
          • 2023-03-19
          • 1970-01-01
          • 2020-12-23
          • 1970-01-01
          • 1970-01-01
          • 2016-09-30
          • 2022-01-19
          相关资源
          最近更新 更多