我正在使用列表视图,其中有一个引用可绘制/列表的 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 的间隙。
请参考下图:
正如您从图像中看到的,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:
为了没有双选择器(并且在适当的位置,例如顶部、底部),您需要处理两种情况,顶部元素(需要顶部和底部的选择器)加上每隔一行仅需要底部的选择器(顶部将被前一个元素的选择器覆盖)。这必须在适配器中用代码完成(如果您使用一个简单的表格,您可以只为顶部元素创建一个可绘制元素,为其他元素创建一个可绘制元素):
- 删除类似的属性
android:top
, android:bottom
等来自layer-list
(因为您将在代码中设置它们)
- in the
getView()
适配器的方法检索行视图的背景(这将是LayerDrawable
)
- 根据您拥有的位置(主要是 0 与任何其他位置)使用
LayerDrawable.setLayerInset()
方法并设置索引为 1 的图层的插图(如果这是您的完整可绘制对象):and第一个元素为底部,其他位置为顶部(值为 0)和底部
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)