【问题标题】:CardView remove borderCardView 移除边框
【发布时间】:2020-08-23 18:46:27
【问题描述】:

我也想删除我的 cardView 上的边框。 我尝试将 elavation 设置为 0 dp , app:cardPreventCornerOverlap 设置为 false 并将 app:cardUseCompatPadding 设置为 true ,但我无法从 CardView 中删除边框 这是我的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:background="@android:color/transparent"
    android:orientation="vertical">

    <androidx.cardview.widget.CardView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@color/IMKAWhite"
        android:layout_gravity="center"
        app:cardPreventCornerOverlap="false"
        app:cardUseCompatPadding="true"
        android:elevation="0dp">

        <RelativeLayout
            android:id="@+id/card"
            android:background="@color/IMKAWhite"
            android:layout_width="150sp"
            android:layout_height="match_parent">

            <ImageView
                android:layout_width="150sp"
                android:layout_height="150sp"
                android:id="@+id/profile_photo"
                android:adjustViewBounds="true"
                android:background="@color/colorPrimary"
                android:layout_centerHorizontal="true" />

            <TextView
                android:layout_below="@+id/profile_photo"
                android:id="@+id/profile_name"
                android:layout_marginTop="10sp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:textStyle="bold"
                android:textColor="@color/background_tutorial"
                android:textSize="@dimen/text_dp_25"
                android:gravity="center"
                android:text="Medium Text"
                android:textAppearance="?android:attr/textAppearanceMedium" />

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/bt_edit_profile"
                android:layout_below="@+id/profile_name"
                android:layout_marginTop="@dimen/text_dp_25"
                android:layout_centerHorizontal="true"
                android:textSize="@dimen/text_dp_16"
                android:padding="5sp"
                android:textColor="@color/background_tutorial"
                android:background="@drawable/ic_bt_edit"
                android:text="@string/edit_profile"
                android:gravity="center" />

        </RelativeLayout>

    </androidx.cardview.widget.CardView>

</LinearLayout>

这是我的屏幕:

我尝试这样做:

  app:cardPreventCornerOverlap="false"
        app:cardUseCompatPadding="true"
        android:elevation="0dp"

但偷我有边界

【问题讨论】:

  • 更改为app:cardElevation="0dp"

标签: android kotlin


【解决方案1】:

使用

card_view:cardElevation="0dp" 而不是android:elevation="0dp"

在根元素中导入命名空间:

xmlns:card_view="http://schemas.android.com/apk/res-auto"

如果您不打算使用高程并且不想在此布局中使用任何边框,只需删除 CardViewelement 并将您的视图保留在您的 RelativeLayout

【讨论】:

    猜你喜欢
    • 2020-07-04
    • 1970-01-01
    • 1970-01-01
    • 2019-03-08
    • 1970-01-01
    • 1970-01-01
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多