2016-03-01 55 views
0

Here is my Image not yet scrolled安卓:ListView的页眉和页脚的行为是不正常

显示这是视图,当我滚动它..它增加了额外的布局,扩大我的列表视图项中的某些空间

enter image description here

我应该分配哪些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

显示你的xml文件 –

+0

我认为你必须发布完整的xml文件。 –

+0

它几乎是700行......它说它超过了允许的字符数。它声明允许的身体是30000个和我的31000 +字符。 – DreamBigAlvin

回答

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.addFooterViewsetupListViewAdapter功能。

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); 
} 
0

第一件事,郁可在列表视图中一个以上的页眉和页脚您的addHeader打电话。每次(),它会加入列表标题视图。在列表项为空的情况下。然后你需要setAdapter(null)。然后只有你将能够看到你添加在页眉和页脚的意见。