【问题标题】:Image goes over border of listview when scrolling滚动时图像越过列表视图的边框
【发布时间】:2015-05-20 23:53:38
【问题描述】:

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

我有一张完美的照片,它不会让我发布它。

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

-戴夫

每个请求的发布代码:

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>

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

    <?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>

【问题讨论】:

  • 如果你不能发布图片,你应该发布你的代码。
  • 图像显示正常,问题是当我滚动列表时它出现在列表视图的边框顶部

标签: android listview android-listview scroll imageview


【解决方案1】:

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

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

然后列表视图将被形状的笔画宽度插入,并且它不应该显示在形状边框的顶部。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-07
    • 2013-01-21
    • 2020-05-29
    • 2014-05-12
    • 2020-02-04
    相关资源
    最近更新 更多