CardView 在底部插入暗线
CardView inserts dark line at bottom
我正在使用 com.android.support:cardview-v7:23.3.0.
在 API < 21 我的 CardView 坚持在底部放置一条黑线,如此处所示
这是我的布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<android.support.v7.widget.CardView
android:id="@+id/category_cardView"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
card_view:cardBackgroundColor="#80d0d0d0"
card_view:cardCornerRadius="30dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/list_item_category_imageImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="3dp"
tools:ignore="contentDescription"
tools:src="@drawable/ic_launcher_find_the_fun" />
<ImageButton
android:id="@+id/list_item_category_listButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="3dp"
android:background="@drawable/button_selector_category"
android:contentDescription="@string/cd_list"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_list_black_24dp" />
<ImageButton
android:id="@+id/list_item_category_mapButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/list_item_category_listButton"
android:background="@drawable/button_selector_category"
android:contentDescription="@string/cd_map"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_map_black_24dp" />
<!-- Title -->
<TextView
android:id="@+id/list_item_category_titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/list_item_category_mapButton"
android:layout_toRightOf="@id/list_item_category_imageImageView"
android:paddingRight="3dp"
android:textSize="17sp"
android:textStyle="bold"
android:typeface="sans"
tools:text="Category Title" />
</RelativeLayout>
</android.support.v7.widget.CardView>
我试过各种方法来删除它。如果我删除包含 "card_view:cardCornerRadius="30dp"" 的行,这就是我所看到的:
如果我明确设置card_view:cardCornerRadius="0dp"
,我看到的和上面的完全一样。
我的布局中的以下变化无法解决此问题(我尝试这些主要是为了调试,而不是因为我真的希望它们有所作为)。
- 我改为使用 card_view:cardUseCompatPadding="false"
- card_view:cardUseCompatPadding="true"
- card_view:cardPreventCornerOverlap="true"
- card_view:cardPreventCornerOverlap="false"
- card_view:contentPadding="0dp"
你能建议这个布局有什么问题,甚至可以尝试调试步骤吗?
您忘记将 below 属性 添加到您的 CardView 并且它有效
XML
card_view:cardElevation="0dp"
或
JAVA
cardView.setCardElevation(0);
cardView.setElevation()
方法和 CardView 属性 android:elevation
将在 Android 5.0
之前的平台中抛出 java.lang.NoSuchMethodError
检查
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<android.support.v7.widget.CardView
android:id="@+id/category_cardView"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
card_view:cardBackgroundColor="#80d0d0d0"
card_view:cardCornerRadius="30dp"
card_view:cardElevation="0dp" //added
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/list_item_category_imageImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="3dp"
tools:ignore="contentDescription"
tools:src="@drawable/ic_launcher_find_the_fun" />
<ImageButton
android:id="@+id/list_item_category_listButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="3dp"
android:background="@drawable/button_selector_category"
android:contentDescription="@string/cd_list"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_list_black_24dp" />
<ImageButton
android:id="@+id/list_item_category_mapButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/list_item_category_listButton"
android:background="@drawable/button_selector_category"
android:contentDescription="@string/cd_map"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_map_black_24dp" />
<!-- Title -->
<TextView
android:id="@+id/list_item_category_titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/list_item_category_mapButton"
android:layout_toRightOf="@id/list_item_category_imageImageView"
android:paddingRight="3dp"
android:textSize="17sp"
android:textStyle="bold"
android:typeface="sans"
tools:text="Category Title" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
我正在使用 com.android.support:cardview-v7:23.3.0.
在 API < 21 我的 CardView 坚持在底部放置一条黑线,如此处所示
这是我的布局。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<android.support.v7.widget.CardView
android:id="@+id/category_cardView"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
card_view:cardBackgroundColor="#80d0d0d0"
card_view:cardCornerRadius="30dp"
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/list_item_category_imageImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="3dp"
tools:ignore="contentDescription"
tools:src="@drawable/ic_launcher_find_the_fun" />
<ImageButton
android:id="@+id/list_item_category_listButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="3dp"
android:background="@drawable/button_selector_category"
android:contentDescription="@string/cd_list"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_list_black_24dp" />
<ImageButton
android:id="@+id/list_item_category_mapButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/list_item_category_listButton"
android:background="@drawable/button_selector_category"
android:contentDescription="@string/cd_map"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_map_black_24dp" />
<!-- Title -->
<TextView
android:id="@+id/list_item_category_titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/list_item_category_mapButton"
android:layout_toRightOf="@id/list_item_category_imageImageView"
android:paddingRight="3dp"
android:textSize="17sp"
android:textStyle="bold"
android:typeface="sans"
tools:text="Category Title" />
</RelativeLayout>
</android.support.v7.widget.CardView>
我试过各种方法来删除它。如果我删除包含 "card_view:cardCornerRadius="30dp"" 的行,这就是我所看到的:
如果我明确设置card_view:cardCornerRadius="0dp"
,我看到的和上面的完全一样。
我的布局中的以下变化无法解决此问题(我尝试这些主要是为了调试,而不是因为我真的希望它们有所作为)。
- 我改为使用 card_view:cardUseCompatPadding="false"
- card_view:cardUseCompatPadding="true"
- card_view:cardPreventCornerOverlap="true"
- card_view:cardPreventCornerOverlap="false"
- card_view:contentPadding="0dp"
你能建议这个布局有什么问题,甚至可以尝试调试步骤吗?
您忘记将 below 属性 添加到您的 CardView 并且它有效
XML
card_view:cardElevation="0dp"
或
JAVA
cardView.setCardElevation(0);
cardView.setElevation()
方法和 CardView 属性 android:elevation
将在 Android 5.0
java.lang.NoSuchMethodError
检查
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<android.support.v7.widget.CardView
android:id="@+id/category_cardView"
android:layout_width="320dp"
android:layout_height="wrap_content"
android:layout_margin="0dp"
card_view:cardBackgroundColor="#80d0d0d0"
card_view:cardCornerRadius="30dp"
card_view:cardElevation="0dp" //added
card_view:cardUseCompatPadding="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/list_item_category_imageImageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="3dp"
tools:ignore="contentDescription"
tools:src="@drawable/ic_launcher_find_the_fun" />
<ImageButton
android:id="@+id/list_item_category_listButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_margin="3dp"
android:background="@drawable/button_selector_category"
android:contentDescription="@string/cd_list"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_list_black_24dp" />
<ImageButton
android:id="@+id/list_item_category_mapButton"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_toLeftOf="@+id/list_item_category_listButton"
android:background="@drawable/button_selector_category"
android:contentDescription="@string/cd_map"
android:padding="10dp"
android:scaleType="fitXY"
android:src="@drawable/ic_map_black_24dp" />
<!-- Title -->
<TextView
android:id="@+id/list_item_category_titleTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toLeftOf="@id/list_item_category_mapButton"
android:layout_toRightOf="@id/list_item_category_imageImageView"
android:paddingRight="3dp"
android:textSize="17sp"
android:textStyle="bold"
android:typeface="sans"
tools:text="Category Title" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</LinearLayout>