2016-03-01 37 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)。然後只有你將能夠看到你添加在頁眉和頁腳的意見。