如何避免列表之间出现双边框?

2023-12-10

我正在使用列表视图,其中有一个引用可绘制/列表的 xml,如下所示:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
 //For the borders
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@color/white" />
            <corners android:radius="0dp" />
        </shape>
    </item>
    //For the background color of cells 
    <item android:top="1px"
          android:left="0dp"
          android:right="0dp"
          android:bottom="1px">
        <shape android:shape="rectangle">
            <solid android:color="#262626" />
            <corners android:radius="0dp" />
        </shape>
    </item>
</layer-list>

上面的代码主要用于定义单元格的边框和背景颜色。但是,我希望能够使用线条而不是矩形作为边框,以便一个矩形的底部边框不会在其下方的另一个矩形的顶部边框之间留下 1 dp 的间隙。 请参考下图:

enter image description here

正如您从图像中看到的,BOK.L 下面的矩形底部边框有点偏离,显示 GOOG.OQ 的顶部矩形边框之间存在间隙,有没有办法解决此问题,使两个边框都重叠在每个边框的顶部其他并且没有出现这样的双线间隙,或者是否有一种方法可以定义线条形状,使其在图片中所有单元格的上方和下方定义而没有间隙?

有什么线索吗?

谢谢! 贾斯汀

引用相同内容(drawable/list)的 xml 文件如下:

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

    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/list"
    android:padding="4dp"
     >



    <TextView
        android:id="@+id/symbol"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="2dp"
        android:paddingLeft="8dp"
        android:textColor="@color/search_autosuggest_header_text"
        foo:customFont="Roboto-Bold.ttf"
        android:singleLine="true"
        android:layout_toLeftOf="@+id/last_container"
        android:ellipsize="end"
        android:gravity="left" 
        android:textSize="14sp"/>

    <TextView
        android:id="@+id/name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingLeft="8dp"
        foo:customFont="Roboto-Regular.ttf"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/symbol"
        android:layout_toLeftOf="@+id/last_container"
        android:paddingBottom="4dp"
        android:textColor="@color/search_autosuggest_item_subtitle"
        android:singleLine="true"
        android:ellipsize="end"
        android:textSize="11sp" />

    <FrameLayout
        android:id="@+id/last_container"
        android:layout_width="87dp"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:layout_toLeftOf="@+id/net_change_container" >

        <TextView
            android:id="@+id/last_back"
            style="@style/TextView.ListsTextView"
            android:layout_width="87dp"
            android:layout_height="wrap_content"
            android:padding="3dp" />

        <TextView
            android:id="@+id/last"
            style="@style/TextView.ListsTextView"
            android:layout_width="87dp"
            android:textSize="12sp"
            android:layout_height="wrap_content" />
    </FrameLayout>


    <FrameLayout
        android:id="@+id/net_change_container"
        android:layout_width="80dp"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:layout_toLeftOf="@+id/percent_change_container" >

        <TextView
            android:id="@+id/net_change_back"
            style="@style/TextView.ListsTextView"
            android:layout_width="80dp"
            android:layout_height="wrap_content"
            android:padding="3dp" />

        <TextView
            android:id="@+id/net_change"
            style="@style/TextView.ListsTextView"
            android:layout_width="80dp"
            android:textSize="12sp"
            android:layout_height="wrap_content" />
    </FrameLayout>

    <FrameLayout
        android:id="@+id/percent_change_container"
        android:layout_width="65dp"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_margin="1dp" >

        <TextView
            android:id="@+id/percent_change_back"
            style="@style/TextView.ListsTextView"
            android:layout_width="65dp"
            android:textSize="14sp"
            foo:customFont="Roboto-Regular.ttf"
            android:layout_height="wrap_content"
            android:padding="3dp" />

        <TextView
            android:id="@+id/percent_change"
            style="@style/TextView.ListsTextView"
            android:layout_width="65dp"
            android:textSize="12sp"
            android:layout_height="wrap_content"/>
    </FrameLayout>

</RelativeLayout>

Also,@jboi with with your fix the screen that I get is: enter image description here


为了没有双选择器(并且在适当的位置,例如顶部、底部),您需要处理两种情况,顶部元素(需要顶部和底部的选择器)加上每隔一行仅需要底部的选择器(顶部将被前一个元素的选择器覆盖)。这必须在适配器中用代码完成(如果您使用一个简单的表格,您可以只为顶部元素创建一个可绘制元素,为其他元素创建一个可绘制元素):

  • 删除类似的属性android:top, android:bottom等来自layer-list(因为您将在代码中设置它们)
  • in the getView()适配器的方法检索行视图的背景(这将是LayerDrawable)
  • 根据您拥有的位置(主要是 0 与任何其他位置)使用LayerDrawable.setLayerInset()方法并设置索引为 1 的图层的插图(如果这是您的完整可绘制对象):and第一个元素为底部,其他位置为顶部(值为 0)和底部
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何避免列表之间出现双边框? 的相关文章

随机推荐

  • 使用 jQuery 搜索 HTML 字符串

    如果我运行这段代码 var html div class bar div console log html find div 如果我运行此代码 我不会返回任何结果 var html div div class bar div div con
  • 单行填充ListView高度

    listView 中有一行我希望其高度与 listView 相同 假设是全屏 行布局看起来像
  • PHP printf 函数及其奇怪的行为

    我很困惑这些数字的含义 对我来说 printf 似乎给了我错误的结果 echo printf 2f 1 1 004 echo printf 3f 1 1 005 echo printf 2f 1 1234 1 124 首先 它似乎打印了太多
  • 使用 JavaScript 解码 URL 参数

    这应该是一个简单的任务 但我似乎找不到解决方案 我有一个基本字符串作为查询字符串参数传递 如下所示 This is a message with spaces 我想使用 JavaScript 解码该参数This is a message w
  • 多任务模型的自定义损失

    我正在微调 keras 模型 该模型为 3 个子任务输出 3 个不同的预测 模型输出是一个列表 out batch size 5 batch size 6 batch size 6 我只想计算第三个输出的分类交叉熵损失 所以我定义了一个简单
  • 检测 UIImageView 上的触摸事件

    我在 UIView 上放置了 4 个 UIImageView 并给它们命名 UIImageView myImg1 UIImageView alloc init UIImageView myImg2 UIImageView alloc ini
  • 在 Visual Studio Code 中调试 Python 时如何使用“跳转到光标”调试器命令

    Python调试器支持跳转命令来设置下一行执行 在 VS Code 中调试 Python 代码时可以使用此功能吗 vscode v1 36 增加了这个 跳转到光标 功能 参见调试 跳转到发行说明中的 光标 跳转到光标处 我们添加了一个新的调
  • 初始化 2D 对象数组时出现空指针异常 [Java]

    我正在尝试制作 2D 图块游戏 在制作保存图块的数组时 我收到 NullPointerException 这里是一些代码 抱歉 如果格式不正确 第一次 公开课世界 holds data for where to place images a
  • 有任何代码/库可以缩小 UIImage 吗?

    是否有任何代码或库可以帮助我缩小图像 如果你用iPhone拍照 它的像素大约是2000x1000 这对网络不太友好 我想将其缩小为 480x320 有什么提示吗 这就是我正在使用的 效果很好 我肯定会关注这个问题 看看是否有人有更好 更快的
  • Ember — 观察记录的创建/删除

    假设我有 2 组独立的控制器 模型 Dog and Cat 现在 每当我创建新的Cat记录 或删除现有的 我想要Dog控制器观察记录的创建 删除以及新记录的创建 删除Cat记录已创建我希望它触发一些操作 例如console log Bark
  • JOINS、EXISTS 或 IN 哪个更好?关于SQL的几个问题

    我有几个关于 SQL 的问题 如何分析一个人的表现 询问 任何内置软件 MSSQL Server 2005 2008 的功能 应该用什么来代替in在查询中这样性能更好 例如 选择 来自查询 课程 在哪里 查询 ID 输入 从查询中选择 en
  • 如何从 otf 或 ttf 文件获取字体名称?

    我在之前的应用程序中使用了自定义字体 文件名是 ProximaNova Regular otf 并加载我刚刚使用的字体 UIFont fontWithName ProximaNova Regular size 20 这非常有效 现在在这个新
  • java jaxb 是如何工作的?

    只是好奇 jaxb 是如何工作的 我有一个注释如下的类 XmlRootElement name MyJaxb Class MyJaxb XmlElement protected String str public void setStr S
  • 如何获取.NET Core 2.0中登录用户的用户ID?

    我使用 NET Core 和 MVC 创建了一个 Angular 2 应用程序 我想知道用户的登录ID 如何在 net core中获取用户的登录ID 这是我的第一个角度应用程序 我使用以下链接开始https blogs msdn micro
  • 通过增强现实寻找餐馆和旅游景点

    在我的应用程序中 我想使用增强现实来查找家庭餐馆等地方 我想要做的是 当我启动应用程序时 相机打开 然后我想找到相机方向的位置 例如 我启动应用程序 我面向东方 手机键盘面向我 即西方 然后是东方向的地方 我已经编写了一些启动相机的代码 请
  • 如何正确地将事件附加到jqGrid“列选择器”的“关闭对话框”?

    我在正确使用 jqGrid 的列选择器插件 小部件的关闭对话框事件时遇到一些问题 这就是我所拥有的 我从 jqGrid 初始化开始 最后附加了列选择器 如下所示 ticketsTable tableWrap jqGrid url datat
  • ASP.NET MVC - 服务器软件要求?

    我今天刚刚了解了 asp net mvc 我想知道服务器端需要什么来托管它 我想是 IIS 6 及更新版本 和 NET 3 5 您还需要什么吗 来自 MSDN 如何 部署 ASP NET MVC 应用程序 基本上你需要 NET 3 5 Sy
  • RoR 4 中带有验证的正则表达式

    有如下代码 class Product lt ActiveRecord Base validates title description image url presence true validates price numericalit
  • 将 Identity 2.0 函数移至存储库类

    我在我的应用程序中使用 Identity 2 0 并希望将数据功能移动到存储库层 例如以下代码 public class ApplicationDbInitializer DropCreateDatabaseIfModelChanges
  • 如何避免列表之间出现双边框?

    我正在使用列表视图 其中有一个引用可绘制 列表的 xml 如下所示