如何在listview底部删除extraspace?

时间:2016-11-25 11:30:50

标签: android listview

我对layout_through.axml的xml视图如下:

<?xml version="1.0" encoding="utf-8"?>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
    android:id="@+id/linear_2"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:weightSum="2">
    <TextView
        android:id="@+id/resultsTextView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:background="@drawable/dual_listview_header_results"
        android:gravity="center"
        android:text="Results"
        android:textStyle="bold"
        android:textSize="@dimen/PortscustomviewresultsTextViewtextsizeCommon"
        android:textColor="@color/WhiteText"
        android:paddingTop="@dimen/PortscustomviewresultsTextViewPaddingTopBottom"
        android:paddingBottom="@dimen/PortscustomviewresultsTextViewPaddingTopBottom" />
    <LinearLayout
        android:id="@+id/linear_3"
        android:orientation="vertical"
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:weightSum="2"
        android:gravity="center"
        android:background="@drawable/dual_listview_header_numberofframes">
        <TextView
            android:id="@+id/noofframeTextView"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginTop="@dimen/PortscustomviewnoofframeTextViewMarginTop"
            android:text="Number of Frames"
            android:textSize="@dimen/PortscustomviewresultsTextViewtextsizeCommon"
            android:textColor="@color/BlackText" />
        <TextView
            android:id="@+id/noofframeTextView1"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:layout_marginBottom="@dimen/PortscustomviewnoofframeTextViewMarginTop"
            android:text="Received of Each Size"
            android:textSize="@dimen/PortscustomviewresultsTextViewtextsizeCommon"
            android:textColor="@color/BlackText" />
    </LinearLayout>
</LinearLayout>
<ListView
    android:id="@+id/loopbackThroughListView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@id/linear_2"
    android:divider="#0188dd00"
    android:dividerHeight="0dp"
    android:paddingLeft="@dimen/PortsloopbackThroughListViewPaddingLeftRight"
    android:paddingRight="@dimen/PortsloopbackThroughListViewPaddingLeftRight"
    android:background="@color/DarkGrey" />
<RelativeLayout
    android:id="@+id/relative_1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_below="@id/loopbackThroughListView"
    android:background="@drawable/dual_list_view_footer_next">
    <TextView
        android:id="@+id/oneOfThreeTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:text="1 of 3"
        android:textStyle="bold"
        android:textSize="@dimen/PortscustomviewresultsTextViewtextsizeCommon"
        android:textColor="@color/WhiteText"
        android:paddingBottom="@dimen/PortscustomviewoneOfThreePaddingTopBottom"
        android:paddingTop="@dimen/PortscustomviewoneOfThreePaddingTopBottom" />
    <TextView
        android:id="@+id/nextTextView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@id/oneOfThreeTextView"
        android:paddingTop="@dimen/PortscustomviewnextTextViewPaddingTop"
        android:paddingRight="@dimen/PortscustomviewnextTextViewPaddingRight"
        android:paddingLeft="@dimen/PortscustomviewnextTextViewPaddingLeft"
        android:clickable="true"
        android:text="Next"
        android:textStyle="bold"
        android:textSize="@dimen/PortscustomviewresultsTextViewtextsizeCommon"
        android:textColor="@color/WhiteText" />
    <ImageView
        android:id="@+id/nextImageView"
        android:src="@drawable/next"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignTop="@id/oneOfThreeTextView"
        android:layout_marginRight="@dimen/PortscustomviewnextImageViewmarginright"
        android:layout_marginTop="@dimen/PortscustomviewnextImageViewmargintop" />
</RelativeLayout>

由于此布局通过LoopbackThroughCustomView.cs类膨胀,因此父级具有xml以下:

<Samsung.Ethernet.AndroidDevice.LoopbackThroughCustomView
    android:id="@+id/loopbackCustomView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentRight="true"
    android:paddingLeft="@dimen/PortsloopbackCustomViewmarginleft"
    android:paddingRight="@dimen/PortsloopbackCustomViewmarginright"
    android:layout_below="@id/loopbackplainTxtView" />  

LoopbackThroughCustomView.cs类中的膨胀代码如下: -

Inflate(Context, Resource.Layout.loopback_through, this);  

适配器列表视图中的膨胀代码如下:

if (view == null)
        {
            holder = new LoopbackThroughViewHolder();
            view = _activity.LayoutInflater.Inflate(Resource.Layout.loopback_through_listitem, parent, false);
            holder.result = view.FindViewById<TextView>(Resource.Id.resultTextView);
            holder.numberofframe = view.FindViewById<TextView>(Resource.Id.numberofframeTextView);
            holder.wrightWrong = view.FindViewById<ImageView>(Resource.Id.tickCrossImageView);
            holder.linear1 = view.FindViewById<RelativeLayout>(Resource.Id.linearLayout1);
            view.Tag = holder;
        }  

listitem的loopback_through_listitem.axml布局如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/loopback_through_listview_background">
<View
    android:id="@+id/lineMiddleTextView"
    android:layout_width="@dimen/Portscustomviewlinewidth"
    android:layout_height="@dimen/PortslistitemlineMiddleTextViewheight"
    android:layout_centerInParent="true"
    android:background="@color/EasyGUIBtnStartColor" />
<TextView
    android:id="@+id/resultTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_toLeftOf="@id/lineMiddleTextView"
    android:layout_marginRight="@dimen/PortslistitemresultTextViewMarginRight"
    android:textSize="@dimen/PortsEasyGUIBtnTextSize"
    android:textColor="@color/BlackText" />
<TextView
    android:id="@+id/numberofframeTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_toRightOf="@id/lineMiddleTextView"
    android:layout_marginLeft="@dimen/PortslistitemresultTextViewMarginRight"
    android:textSize="@dimen/PortsEasyGUIBtnTextSize"
    android:textColor="@color/BlackText" />
<ImageView
    android:id="@+id/tickCrossImageView"
    android:src="@drawable/green_check"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerInParent="true"
    android:layout_alignParentRight="true"
    android:layout_marginRight="@dimen/PortslistitemresultTextViewMarginRight" />

现在的问题是,当我将分频器高度赋予&#34; 0dp&#34;在loopback_through.axml的listview中,然后出现listview底部的一个小额外空间(betwn listview和相对布局),当我给分隔符高度为&#34; 1dp&#34;列表视图内容占据底部空间,没有看到空间,这是我需要的解决方案。我想知道为什么在listview中看到这种类型的行为是通过保持相对布局在listview下面给分隔高度为0dp有任何其他方式来占用底部空间,我尝试给相对布局提供负marginTop但这对所有人来说都不是完美的装置。
我想通过将分隔符高度保持为0dp并将相对布局保持为layout_below listview而不给出任何上边距或下边距来消除listview中的额外底部空间。三江源。

1 个答案:

答案 0 :(得分:0)

在xml代码中添加以下行:

android:footerDividersEnabled="false"

它将删除列表视图中显示为空格的最后一个页脚分隔符。

快乐编码!!!