【发布时间】:2016-11-25 19:37:15
【问题描述】:
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);
Adapter中listview的膨胀代码如下:
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" />
现在的问题是,当我在 loopback_through.axml 中的 listview 中将分隔线高度指定为“0dp”时,listview 底部会出现一个小的额外空间(在 listview 和相对布局之间),并且当我将分隔线高度指定为“ 1dp”然后listview内容占据底部空间,看不到空间,这是我需要的解决方案。我想知道为什么在listview中看到的这种行为有任何其他方法可以通过将相对布局保持在listview下方,将分隔高度设置为0dp来占据底部空间,我尝试将负marginTop赋予相对布局,但这并不适合所有人设备。
我想通过将分隔线高度保持为 0dp 并将相对布局保持为 layout_below listview 并且不提供任何上边距或下边距来消除列表视图中的额外底部空间。谢谢。
【问题讨论】: