xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="260dp"
android:orientation="vertical">
<LinearLayout
android:id="@+id/linear"
android:layout_width="match_parent"
android:layout_height="130dp"
android:orientation="vertical"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="130dp"
android:background="@drawable/bg_space"
android:visibility="visible"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="260dp"
android:background="#ffbbaa">
<HorizontalScrollView
android:id="@+id/horizontal_scrollview"
android:layout_width="wrap_content"
android:layout_height="260dp"
android:background="@color/black"
>
<LinearLayout
android:id="@+id/custom_scroller_llyt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:scrollbars="none">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_launcher"/>
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
如上布局代码,当HorizontalScrollView中的子控件添加的比较多时,HorizontalScrollView的宽度会超出屏幕并且开始能够滑动,但是我在滑动HorizontalScrollView的时候,页面中其他不属于HorizontalScrollView的元素也会受它的影响,就比如上面代码中的linear这个LinearLayout也会跟着一块滑动,这不是我想要的效果。
有尝试过去限定HorizontalScrollView的宽度,然而一限定,它就失去了滑动效果。
求问有没有办法让其不受影响,HorizontalScrollView滑动归它自己滑动,不影响页面中其他元素,急~
http://blog.csdn.net/antimage08/article/details/50527268
你的horizontalscrollview里面嵌入了Linearlayout而且该linearlayout的布局是horizontal的,这自然出产生滑动冲突。这种事情在android布局中可能常常会使用到,
我以前就遇到高scrollview里面嵌套listview的事件,你需要android滑动事件传播机制。这是我以前写的一个小程序,http://download.csdn.net/download/qq_21112811/9516700,解决了scrollview嵌套listview的情况,
你可以参考一下。详细了解的话,可以查看android源码或者博客,不过推荐看博客,因为最新的android源码不太容易看懂。
在 horizontalscrollview里面重写这个方法 onInterceptTouchEvent,这个方法是专门拦截父控件到子控件事件传递的。当horizontalscrollview滑动时,onInterceptTouchEvent直接返回true,他的子控件就没事件了