日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android开发之解决ListView和ScrollView滑动冲突的方法

發布時間:2023/12/15 Android 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android开发之解决ListView和ScrollView滑动冲突的方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

我們看下圖:

?

不管怎么滑動都無法顯示listview的剩余數據,只能顯示一條,我們看下布局,ScrollView里面嵌套ListView

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"xmlns:app="http://schemas.android.com/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滑动冲突的方法的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。