作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在使用 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"
,我会看到与上面完全相同的结果。
我的布局中的以下变体没有解决这个问题(我尝试这些主要是为了调试,而不是因为我真的希望它们有所作为)。
你能建议这个布局有什么问题,甚至可以尝试调试步骤吗?
最佳答案
您忘记将 below 属性 添加到您的 CardView 并且它可以工作
XML
card_view:cardElevation="0dp"
或
Java
cardView.setCardElevation(0);
cardView.setElevation()
方法和 CardView 属性 android:elevation
会抛出 java.lang.NoSuchMethodError
Android 5.0之前的平台
检查
<?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>
关于android - CardView 在底部插入暗线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36931207/
我是一名优秀的程序员,十分优秀!