我们看下图:
不管怎么滑动都无法显示listview的剩余数据,只能显示一条,我们看下布局,ScrollView里面嵌套ListView
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="/apk/res/android"xmlns:app="/apk/res-auto"android:layout_width="match_parent"android:layout_height="match_parent"android:background="@null"android:orientation="vertical"><include layout="@layout/common_title_view" /><ScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:scrollbars="none"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="match_parent"android:background="@null"android:orientation="vertical"><LinearLayoutandroid:layout_width="match_parent"android:layout_height="@dimen/dp_44"android:background="@color/colorMain"><ImageViewandroid:id="@+id/iv_pre"android:layout_width="0dp"android:layout_height="match_parent"android:layout_centerVertical="true"android:layout_weight="1"android:background="@null"android:paddingRight="@dimen/dp_60"android:scaleType="centerInside"android:src="@mipmap/ic_left_arrow" /><TextViewandroid:id="@+id/tv_current_time"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_gravity="center_vertical"android:text="1970-01-01"android:textColor="@color/white" /><ImageViewandroid:id="@+id/iv_more"android:layout_width="0dp"android:layout_height="match_parent"android:layout_centerVertical="true"android:layout_weight="1"android:background="@null"android:paddingLeft="@dimen/dp_60"android:scaleType="centerInside"android:src="@mipmap/ic_right_arrow" /></LinearLayout><com.Yhsh.mobile.uiwidget.widget.calendar.CalendarLayoutandroid:layout_width="match_parent"android:layout_height="0dp"android:layout_weight="1"android:orientation="vertical"app:calendar_show_mode="only_week_view"app:default_status="shrink"><com.Yhsh.mobile.uiwidget.widget.calendar.CalendarViewandroid:id="@+id/scheduling_calendar_view"android:layout_width="match_parent"android:layout_height="wrap_content"android:background="@color/colorMain"app:calendar_height="60dp"app:current_day_lunar_text_color="@color/white"app:current_day_text_color="@color/white"app:current_month_text_color="@color/white"app:day_text_color="@color/white"app:day_text_size="14sp"app:lunar_text_size="14sp"app:month_view_show_mode="mode_only_current"app:other_month_text_color="@color/white"app:selected_lunar_text_color="@color/white"app:selected_text_color="@color/white"app:week_background="@color/colorMain"app:week_start_with="sun"app:week_text_color="@color/white"app:week_text_size="14sp" /></com.Yhsh.mobile.uiwidget.widget.calendar.CalendarLayout><TextViewandroid:id="@+id/tv_scheduling_date"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_marginTop="15dp"android:paddingLeft="15dp"android:paddingRight="15dp"android:textColor="@color/black" /><ListViewandroid:divider="@null"android:id="@+id/lv_replace_over_time_list"android:layout_width="match_parent"android:layout_height="wrap_content" /></LinearLayout></ScrollView></LinearLayout>
实际上解决方法非常简单如下:
/*** 设置点击日期显示班次的方法** @param selectPosition 选中的日期*/private void setSelectData(int selectPosition) {myReplaceAdapter = new MyReplaceAdapter(mSchedulingTimeMap, selectPosition);lvReplaceOverTimeList.setAdapter(myReplaceAdapter);setHeight();}/*** 解决ListView和ScrollView滑动冲突的bug* lvReplaceOverTimeList 控件listView* myReplaceAdapter adapter*/public void setHeight() {int height = 0;int count = myReplaceAdapter.getCount();for (int i = 0; i < count; i++) {View temp = myReplaceAdapter.getView(i, null, lvReplaceOverTimeList);temp.measure(0, 0);height += temp.getMeasuredHeight();}ViewGroup.LayoutParams params = lvReplaceOverTimeList.getLayoutParams();params.width = ViewGroup.LayoutParams.FILL_PARENT;params.height = height;lvReplaceOverTimeList.setLayoutParams(params);}
再来看下是否可以滑动:
看到了吧,余下的数据显示出来了
如果觉得《Android开发之解决ListView和ScrollView滑动冲突的方法》对你有帮助,请点赞、收藏,并留下你的观点哦!