Android 具有两个listview和标头的视图将移动另一个listview

Android 具有两个listview和标头的视图将移动另一个listview,android,android-listview,Android,Android Listview,在我的视图中,我有两个ListView,它们都有一个标题。当我滚动一个列表时,另一个listview也会移动(不是很多),但它在标题不再可见的地方移动得足够多 但是,如果我删除标题,则不会发生这种情况 在我的xml中,我设置了android:splitMotionEvents=“true”,但这并没有起任何作用 这是我在ListView中设置标题的方式 @Override public View onCreateView(LayoutInflater inflater,ViewGroup con

在我的视图中,我有两个ListView,它们都有一个标题。当我滚动一个列表时,另一个listview也会移动(不是很多),但它在标题不再可见的地方移动得足够多

但是,如果我删除标题,则不会发生这种情况

在我的xml中,我设置了
android:splitMotionEvents=“true”
,但这并没有起任何作用

这是我在ListView中设置标题的方式

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle saved){
    View v = inflater.inflate(R.layout.sin_preplan_layout,container,false);

    sinList = (ListView)v.findViewById(R.id.sin_listView);
    prePlanList = (ListView)v.findViewById(R.id.preplan_listView);

    sinList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    prePlanList.setChoiceMode(ListView.CHOICE_MODE_SINGLE);

    View v2 = inflater.inflate(R.layout.sin_preplan_header,(ViewGroup) v.findViewById(R.id.header_layout_root));

    prePlanList.setHeaderDividersEnabled(true);
    prePlanList.addHeaderView(v2);
    sinList.addHeaderView(v2);

    return v;
}

关于为什么会发生这种情况,您有什么想法吗?

您正在将同一个实例两次添加到不同的视图中,这是不鼓励的。试试这个:

View firstHeader = inflater.inflate(R.layout.sin_preplan_header,(ViewGroup) v.findViewById(R.id.header_layout_root));
prePlanList.addHeaderView(firstHeader);

View secondHeader = inflater.inflate(R.layout.sin_preplan_header,(ViewGroup) v.findViewById(R.id.header_layout_root));
sinList.addHeaderView(secondHeader);