Java 如何在Scrollview中设置Listview,然后设置一个类似分隔符的文本视图,然后再次设置Listview

Java 如何在Scrollview中设置Listview,然后设置一个类似分隔符的文本视图,然后再次设置Listview,java,android,xml,Java,Android,Xml,如何设置Listview,然后设置一个文本视图(如分隔符),然后在Scrollview中再次设置Listview,这两个Listview的行为类似于一个Listview我如何设置这两个Listview有两个不同的适配器和布局您试图实现的是可行的,但是会有很多UI问题,因为您试图将2个Listview放入Scrollview中scrollview和listview都将处于活动状态,所以您可以不使用scrollview,只使用LinearLayout中的listview 检查以下代码: <

如何设置Listview,然后设置一个文本视图(如分隔符),然后在Scrollview中再次设置Listview,这两个Listview的行为类似于一个Listview我如何设置这两个Listview有两个不同的适配器和布局您试图实现的是可行的,但是会有很多UI问题,因为您试图将2个Listview放入Scrollview中scrollview和listview都将处于活动状态,所以您可以不使用scrollview,只使用LinearLayout中的listview

检查以下代码:

  <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:weightSum="1"
        >

        <ListView
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.45"></ListView>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.10"
            android:gravity="center"
            />

        <ListView
            android:layout_width="match_parent"
            android:layout_height="0dip"
            android:layout_weight="0.45"></ListView>

    </LinearLayout>

不要将ListView嵌套到ScrollView中,即使是两个ListView

通过使用特殊适配器,您只能使用一个ListView来实现此效果

在此适配器中,必须重写getItemViewType和getViewTypeCount方法

在getItemViewType(int-position)中,您可以定义3种int类型来按位置表示这3种类型的视图,0类型:您的第一个listview项目,1类型:中间的TextView,2类型:第二个listview。 比如:



到目前为止,您尝试了什么?请先发布您的代码。在Scrollview中使用Listview无法正常工作,请使用NestedScrollViewplz检查屏幕快照我添加屏幕快照plz检查,然后告诉meya,上述代码只执行f9操作,没有任何UI问题!两个listview都在scrollview中,,两个listview的工作都很好,但我只想当我向下滚动到顶部时,两个listview同时滚动,就像一个listview一样,这就是我要讨论的问题,因为屏幕捕捉到了右侧的触摸,android屏幕上只有6-10个触摸点,因此listview将滚动……这就是为什么不喜欢使用它的原因好的,我知道了,但如果你有任何像这样的解决方案,请与我分享在互联网上发现的解决方案,我搜索了两天,这是我的布局设计
    public int getItemViewType(int position){
         if (position < list1.size()) return 1;//item in list1
         else if (position == list1.size) return 2;//textview
         else return 3;//item in list2
    }
 public int getCount(){
    return list1.size() + 1 + list2.size();
 }
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      xmlns:android="http://schemas.android.com/apk/res/android">
      <ListView
          android:id="@+id/lvChildCategory"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"/>

      <TextView
          android:id="@+id/tv"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="All Service and Task"
          android:gravity="center"
          android:background="#969191"
          android:textColor="#fff"
          android:layout_below="@+id/lvChildCategory"
          android:textAppearance="@style/Base.TextAppearance.AppCompat.Large"/>

      <ListView
          android:id="@+id/lvServiceAndTask"
          android:layout_below="@+id/tv"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"/>


  </RelativeLayout>