滚动时图像越过列表视图的边框

Image goes over border of listview when scrolling

我在列表视图中创建了多个项目。列表视图中的每个项目都由一个带有两行 table 的自定义适配器组成。我在适配器 table 的行中有图像和文本。当我滚动列表视图时,每一行的内容都超出了列表视图的边界。这让我的强迫症变得疯狂。提前致谢。

我对此有一张完美的照片,它不会让我 post 它。

所有这些都是新手,感谢您的耐心等待。

-戴夫

post每个请求的编码:

Shape.xml,定义列表视图的边框

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" 
    android:color="@color/white_text">

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

    <stroke
        android:width="2dp"
        android:color="@color/border_color" />


</shape>

定义每个列表条目的游戏table

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

    <TableRow
        android:id="@+id/tableRow1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="5dp" >

        <ImageView
            android:id="@+id/awayLogo"
            android:layout_height="25dp"
            android:layout_width="50dp"
            android:paddingLeft="2dp"
            android:paddingRight="2dp"
            android:paddingTop="2dp"
            android:paddingBottom="2dp"
            android:gravity="center" />

        <TextView
            android:id="@+id/awayName"
            android:layout_width="150dp"
            android:textSize="22dp"
            android:gravity="left"
            android:textColor="#000000" />

        <TextView
            android:id="@+id/awayScore"
            android:layout_width="45dp"
            android:textSize="22dp"
            android:gravity="center"
            android:textColor="#000000" />
        <TextView
            android:id="@+id/awayTime"
            android:layout_width="48dp"
            android:textSize="12dp"
            android:gravity="center"
            android:textColor="#000000" />
    </TableRow>
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="5dp" >

        <ImageView
            android:id="@+id/homeLogo"
            android:layout_height="25dp"
            android:layout_width="50dp"
            android:paddingLeft="2dp"
            android:paddingRight="2dp"
            android:paddingTop="2dp"
            android:paddingBottom="2dp"
            android:gravity="center" />

        <TextView
            android:id="@+id/homeName"
            android:layout_width="150dp"
            android:textSize="22dp"
            android:gravity="left"
            android:textColor="#000000" />

        <TextView
            android:id="@+id/homeScore"
            android:layout_width="45dp"
            android:textSize="22dp"
            android:gravity="center"
            android:textColor="#000000" />
        <TextView
            android:id="@+id/homeTime"
            android:layout_width="48dp"
            android:textSize="12dp"
            android:gravity="center"
            android:textColor="#000000" />
    </TableRow>

</TableLayout>

你没有 post xml 实际上显示 @drawable/shape 作为你的背景,但我可以提出建议。

  • 添加另一个包含列表视图的布局。
  • 将包装器布局的背景设置为@drawable/shape
  • 在包装器布局上设置 android:padding="2dp"

然后列表视图将插入形状笔划宽度的量,它不应显示在形状边框的顶部。