Android 卡片 View 在卡片之间有细灰线

标签 android android-xml

我有一个 android ListView ,它显示类似卡片的 View ,正如您在这张图片中看到的,我的卡片之间有一条灰色细线:

enter image description here

我怎样才能摆脱灰线?

我实现这个卡片 View 的xml是这样的:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:layout_height="wrap_content">

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="6dp"
        android:layout_marginRight="6dp"
        android:layout_marginTop="4dp"
        android:layout_marginBottom="4dp"
        android:orientation="vertical"
        android:background="@drawable/bg_card">

    <!-- Card Contents go here -->

    <TextView
            android:id="@+id/beerNameList"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
            android:id="@+id/beerBreweryNameList"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />

</LinearLayout>

</FrameLayout>

bg_card.xml:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle"
               android:dither="true">

            <corners android:radius="2dp"/>

            <solid android:color="#ccc" />

        </shape>
    </item>

    <item android:bottom="2dp">
        <shape android:shape="rectangle"
               android:dither="true">

            <corners android:radius="2dp" />

            <solid android:color="@android:color/white" />

            <padding android:bottom="8dp"
                     android:left="8dp"
                     android:right="8dp"
                     android:top="8dp" />
        </shape>
    </item>
</layer-list>

尝试改变分隔高度,这是我的代码,它没有去掉灰线:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <LinearLayout
        android:id="@+id/linlaHeaderProgress"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone" >

        <ProgressBar
            android:id="@+id/pbHeaderProgress"
            style="android@style/Spinner"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >
        </ProgressBar>
    </LinearLayout>

    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:dividerHeight="0px"
        >
    </ListView>

</LinearLayout>

最佳答案

dividerHeight 应该有效。作为解决方法,您可以将分隔线的颜色更改为背景色或透明色

<ListView 
 android:id="@+id/android:list"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:divider="#E6E6E6"
 android:dividerHeight="0px"/>

你也可以试试这个技巧:

 android:divider="@null"

关于Android 卡片 View 在卡片之间有细灰线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18731268/

相关文章:

Android 谷歌地图在 Nexus S 上崩溃

java - RecyclerView 中的 Admob 原生广告

android - 在应用程序更新中不适用于应用程序包 apk

android - 将星形样式应用于Android中的复选框

java - 对话框中的通用 onclick 监听器

android - ContentProvider 与 SQlite : Same query different result

xml中的Android导航栏大小

Android - 旋转切掉形状的角

android - 如何在 Android 中将解析的 Xml 数据显示到 ListView 中

android: 不自动显示软键盘