gpt4 book ai didi

android - CardView 在底部插入暗线

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:08:39 30 4
gpt4 key购买 nike

我正在使用 com.android.support:cardview-v7:23.3.0。

API < 21 上,我的 CardView 坚持在底部放置一条黑线,如此处所示

enter image description here

这是我的布局。

<?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""的行,这就是我所看到的:

enter image description here

如果我明确设置 card_view:cardCornerRadius="0dp",我会看到与上面完全相同的结果。

我的布局中的以下变体没有解决这个问题(我尝试这些主要是为了调试,而不是因为我真的希望它们有所作为)。

  1. 我改为使用 card_view:cardUseCompatPadding="false"
  2. card_view:cardUseCompatPadding="true"
  3. card_view:cardPreventCornerOverlap="true"
  4. card_view:cardPreventCornerOverlap="false"
  5. card_view:contentPadding="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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com