【问题标题】:Java Android Remove the outline of items in a recyclervciewJava Android 删除回收站中的项目大纲
【发布时间】:2021-10-02 16:01:41
【问题描述】:

我正在开发一个在我的 Firebase 实时数据库中搜索用户的活动,并且我正在使用 cradview 作为布局来膨胀:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="90dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:backgroundTint="#FFFFFF"
    android:elevation="0dp"
    android:layout_marginBottom="20dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

    <androidx.cardview.widget.CardView
        android:id="@+id/crdProfileImage"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp"
        app:cardBackgroundColor="@color/textC"
        app:cardCornerRadius="30dp">

        <ImageView
            android:id="@+id/imgHolder"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/user_default"
            android:scaleType="centerCrop"/>
    </androidx.cardview.widget.CardView>

    <TextView
        android:id="@+id/txtUsername"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/black"
        android:layout_marginTop="5dp"
        android:fontFamily="sans-serif"
        android:textStyle="bold"
        android:layout_toEndOf="@+id/crdProfileImage"
        android:layout_marginLeft="25dp"
        android:textSize="25dp"/>

        <TextView
            android:id="@+id/txtBio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:layout_alignStart="@+id/txtUsername"
            android:layout_marginTop="35dp"
            android:text="Hi, this is my biography."/>




    </RelativeLayout>
</com.google.android.material.card.MaterialCardView>

但是,我注意到当recyclerview输出item时,item出现了一个轮廓:

我以为是海拔,所以我在recyclerview和cardview的布局上都设置为0,但结果没有改变。有人知道怎么解决吗?

编辑:

我试图删除边距底部,但它仍然显示高度:

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.card.MaterialCardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="90dp"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:card_view="http://schemas.android.com/tools"
    android:backgroundTint="#FFFFFF"
    card_view:cardElevation="0dp"
    >

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

    <androidx.cardview.widget.CardView
        android:id="@+id/crdProfileImage"
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="5dp"
        app:cardElevation="0dp"
        app:cardBackgroundColor="@color/textC"
        app:cardCornerRadius="30dp">

        <ImageView
            android:id="@+id/imgHolder"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/user_default"
            android:scaleType="centerCrop"/>
    </androidx.cardview.widget.CardView>

    <TextView
        android:id="@+id/txtUsername"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Username"
        android:textColor="@color/black"
        android:layout_marginTop="5dp"
        android:fontFamily="sans-serif"
        android:textStyle="bold"
        android:layout_toEndOf="@+id/crdProfileImage"
        android:layout_marginLeft="25dp"
        android:textSize="25dp"/>

        <TextView
            android:id="@+id/txtBio"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="@color/black"
            android:layout_alignStart="@+id/txtUsername"
            android:layout_marginTop="35dp"
            android:text="Hi, this is my biography."/>




    </RelativeLayout>
</com.google.android.material.card.MaterialCardView>

【问题讨论】:

    标签: java android xml android-recyclerview android-cardview


    【解决方案1】:

    使用

    card_view:cardElevation="0dp"
    

    代替

    android:elevation="0dp"
    

    【讨论】:

    • 我刚刚尝试过,但是在删除 cardview 中的高程时,当它们是 recyclerview 输出中的项目时,它不会从 cardviews 中删除高程,高程只会从项目布局中删除。不知道我有没有说清楚
    【解决方案2】:

    添加以下代码行以禁用outlineProvider

    android:outlineProvider="none"
    

    【讨论】:

      【解决方案3】:

      除了android:elevation0dp 之外,只需从&lt;com.google.android.material.card.MaterialCardView /&gt; 中删除android:layout_marginBottom="20dp",然后为您的孩子在其中添加android:padding 以使间距

      【讨论】:

      • 我只是尝试这样做(我在问题中发布了更新的代码)但它不起作用
      • 能否将MaterialCardView的高度设置为wrap content再试一下,相对布局也必须有wrap content的高度
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-09
      • 2017-05-02
      • 1970-01-01
      • 2023-03-27
      • 1970-01-01
      • 2017-04-18
      • 1970-01-01
      相关资源
      最近更新 更多