如何避免表之间的双重边界? [英] How do I avoid double borders between lists?

查看:78
本文介绍了如何避免表之间的双重边界?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是列表视图中,我有一个XML引用绘制/名单如下:

I am using a list view in which I have an xml referencing drawable/list as follows:

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

以上code基本上是用来定义边界和单元格的背景颜色。不过,我希望能够用线为边界,而不是矩形,这样一个四边形的底边框犯规离开它下面的一个矩形的上边框之间的1 DP的差距。 请参考下图: ![在此输入图片说明] [1]

The above code is basically used to define the borders and the background color of cells. However, I want to be able to use line for the borders instead of rectangle so that the bottom border of one rectangle doesnt leave a 1 dp gap between the top border of another rectangle below it. Please refer the image below: ![enter image description here][1]

正如你从图片看,下面BOK.L矩形底部边框是有点偏离显示GOOG.OQ顶部矩形边框之间的差距有没有办法解决这个问题,使双方的边界或者重叠的对方的顶部,并没有这样的双线差距似乎还是有办法,我可以定义线的形状,使得它上面的所有的细胞在PIC定义如下没有差距?

As you can see from the image, the rectangular bottom border below BOK.L is a little off showing a gap between the top rectangular border of GOOG.OQ Is there a way to fix this such that both the borders either overlap on top of each other and no such double line gap appears or is there a way I can define a line shape such that it is defined above and below all the cells in the pic without a gap?

任何线索?

谢谢! 贾斯汀

在XML文件中引用相同的(绘制/列表)如下:

The xml file referencing the same (drawable/list) is as follows :

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

此外,@​​ jboi与你的修复,我得到的画面是:  ![在此输入图片说明] [2]

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

推荐答案

为了不有双重选择(在适当的位置也似的在顶部,底部),你有你需要处理,这两种情况顶部元件(其需要选择器的顶部和底部)以及,需要选择器仅在底部每隔一行(顶端将被覆盖的previous元件的选择器)。这必须在code做的,在你的适配器(如果你使用,你可以刚刚做了一个可拉伸的顶级元素,一个用于其他元素的简单表):

In order to not have double selectors(and in proper positions like also at the top, at the bottom) you have two cases that you need to tackle, the top element(which needs the selector at the top and bottom) plus every other row which needs the selector only at the bottom(the top will be covered by the selector of the previous element). This has to be done in code, in your adapter(if you were using a simple table you could have just made one drawable for the top element and one for the other elements):

  • 删除像 Android的特性:顶部安卓底部等从层-list (因为你会设置那些code)
  • 在适配器的 getView()方法检索该行视图的背景(这将是一个 LayerDrawable
  • 基于你有(主要是0对任何oher位置)的位置使用 LayerDrawable.setLayerInset()方法,设置插入索引为1层(如果这是您的完整绘制):前底部的第一个元素,顶部(为0的值),底部为所有其他位置
  • remove the properties like android:top, android:bottom etc from the layer-list(as you'll be setting those in code)
  • in the getView() method of the adapter retrieve the background of the row view(which will be a LayerDrawable)
  • based on the position you have(mainly 0 vs any oher position) use the LayerDrawable.setLayerInset() method and set the inset for the layer with index 1(if that is your complete drawable): top and bottom for the first element, top(with a value of 0) and bottom for every other position

这篇关于如何避免表之间的双重边界?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆