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

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

ScrollView嵌套ViewPager,ViewPage动态设置高度,嵌套事件冲突——滑动冲突解决方法

發(fā)布時(shí)間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ScrollView嵌套ViewPager,ViewPage动态设置高度,嵌套事件冲突——滑动冲突解决方法 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

1、創(chuàng)建自定義ViewPager

?

public class ViewPagerForScrollView extends ViewPager {int myh=0 ;boolean ifme =false;public ViewPagerForScrollView(Context context) {super(context);Log.i("lgq","高度==111= " );}public ViewPagerForScrollView(Context context, AttributeSet attrs) {super(context, attrs);Log.i("lgq","高度==22== " );TestObServernotice.getInstance().addObserver(deleteObserver);}private Observer deleteObserver = new Observer() {@Overridepublic void update(int id, int intparam, String param, Bitmap bitmap) {if (id == 111) {myh = intparam;ifme = true;}}};@Overrideprotected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {int height = 0;if (ifme){View child = getChildAt(myh);child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));int h = child.getMeasuredHeight();height = h;}else {for (int i = 0; i < getChildCount(); i++) {View child = getChildAt(i);child.measure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));int h = child.getMeasuredHeight();Log.i("lgq","高度==== " +h);if (h > height)height = h;}}heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY); // heightMeasureSpec = MeasureSpec.makeMeasureSpec(h, MeasureSpec.EXACTLY);super.onMeasure(widthMeasureSpec, heightMeasureSpec);} }

2、ScrollView屬性

<ScrollViewandroid:layout_width="match_parent"android:layout_height="match_parent"android:focusable="true"android:focusableInTouchMode="true">

?

3、通知刷新viewpager的高度

@Override public void onPageSelected(int i) {mViewPager.requestLayout();TestObServernotice.getInstance().notifyObserver(111, i, "6666", null);Log.i("lgq","經(jīng)理===== "+i); }

?

?

?實(shí)現(xiàn)樣式

長(zhǎng)高度內(nèi)容? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?短高度內(nèi)容

??

?

實(shí)現(xiàn)demo:https://download.csdn.net/download/meixi_android/12390494

bug交流:qq1085220040

?

解決事件沖突方法:

自定義重寫(xiě)View添加如下方法

?

public void setNestedpParent(ViewGroup parent) {this.parent = parent; }

?

@Overridepublic boolean dispatchTouchEvent(MotionEvent event) { // LgqLogutil.e("分發(fā)listview2222222");if (parent != null) {parent.requestDisallowInterceptTouchEvent(true);}return super.dispatchTouchEvent(event);}

?

設(shè)置事件攔截——停止事件傳遞

HorizontalListView horizontalListView = holder.getView(R.id.myhoriz); horizontalListView.setNestedpParent((ViewGroup)horizontalListView.getParent());

?

?

總結(jié)

以上是生活随笔為你收集整理的ScrollView嵌套ViewPager,ViewPage动态设置高度,嵌套事件冲突——滑动冲突解决方法的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。