当我滚动它时,这是视图..它添加了额外的布局,扩展了我的listview项目中的一些空间
我应该分配哪些listview属性来修复它?
这是我的列表视图
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:scrollbarStyle="outsideOverlay"
android:overScrollMode="never"
android:saveEnabled="false" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/relativeHeader"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:cacheColorHint="@android:color/transparent" >
<LinearLayout
android:id="@+id/linearNumber"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="10dp"
android:paddingBottom="5dp"
android:paddingTop="5dp" >
<TextView
android:id="@+id/textViewNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:text="Number: "
android:textStyle="bold"
android:textColor="#000000" />
<TextView
android:id="@+id/textViewNumberValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|left"
android:text="222-222-222-222"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
我对ListView的初始化
private void setupListViewAdapter(ListView listView, View headerView, View footerView){
listView.setDividerHeight(5);
listView.setFadingEdgeLength(200);
listView.addHeaderView(headerView, null, false);
listView.addFooterView(footerView, null, false);
listView.setFastScrollEnabled(false);
listView.setAdapter(mDataAdapter);
}
答案 0 :(得分:0)
此代码使我的列表视图显示不需要的视图。
private void initListView(LayoutInflater inflater, ViewGroup container) {
View headerViewROR = inflater.inflate(R.layout.vp_ror_header, null,false);
View footerViewROR = inflater.inflate(R.layout.vp_remarks_footer, null,false);
listView.addHeaderView(headerViewROR, null, false); //--> multiple occurrence need to be removed
listView.addFooterView(footerViewROR, null, false); //--> multiple occurrence need to be removed
setupListViewAdapter(listView, headerViewROR,footerViewROR);
}
初始化添加页眉和页脚两次导致listview行为..因为我还将 listView.addFooterView 调用到我的 setupListViewAdapter 函数。
private void setupListViewAdapter(ListView listView, View headerView, View footerView){
listView.setDividerHeight(5);
listView.setFadingEdgeLength(200);
listView.addHeaderView(headerView, null, false);//--> here is another assignment
listView.addFooterView(footerView, null, false);//--> here is another assignment
listView.setScrollingCacheEnabled(false);
listView.requestFocus(0);
listView.setAdapter(mDataAdapter);
}
答案 1 :(得分:0)
首先,yu在列表视图中可以有多个页眉和页脚。每次调用addHeader()时,它都会在列表标题中添加视图。在一种情况下,您的列表项是空的。然后你需要setAdapter(null)。然后你才能看到你在页眉和页脚中添加的视图..