解决VideoView等视频播放控件在ViewPager使用,并嵌套在ScrollView里,视频播放时不能滚动到界面底部的问题,同时也解决ScrollView自动滑到底部、中间或listView的头部的问题
一。方法一:
1.代码:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/scrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="360dp"> <android.support.v4.view.ViewPager android:id="@+id/fragment_viewpager" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:id="@+id/fragment_dot" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignBottom="@id/fragment_viewpager" android:layout_marginBottom="10dp" android:gravity="center_horizontal" android:orientation="horizontal" /> </RelativeLayout>
。。。。。。。。。
</ScrollView>
2.解决方法:
listDetails = (ListView) view.findViewById(R.id.fragment_goods_listdetails); listAssess = (ListView) view.findViewById(R.id.fragment_goods_listassess); listStock = (ListView) view.findViewById(R.id.fragment_goods_liststock); listPeer = (ListView) view.findViewById(R.id.fragment_goods_listPeer); // //解决scrollView就会自动滑到底部或者中间部分的问题 // listDetails.setFocusable(false); // listAssess.setFocusable(false); // listStock.setFocusable(false); // listPeer.setFocusable(false); //当一个scrollView 里面包含很多childView,并且整个界面超出屏幕的范围,而且每个childView都获取焦点,scrollView就会自动滑到底部或者中间部分 scrollView = (ScrollView) view.findViewById(R.id.scrollView); //start***以下两个设置结合:解决视频播放或暂停时,界面不能滚动到底部只能滚动到视频显示屏的底部的问题;解决scrollView就会自动滑到底部或者中间部分的问题**start //本身先对焦点进行处理,如果没有处理则分发给child View进行处理,会让所有子View无法获取焦点 scrollView.setDescendantFocusability(ViewGroup.FOCUS_BEFORE_DESCENDANTS); scrollView.setFocusableInTouchMode(true);//设置焦点在scrollView上 //end***************解决视频播放或暂停时,界面不能滚动到底部只能滚动到视频显示屏的底部*************end
二。方法二和方法三:
1.代码:
<com.vip.group.widget.VideoFragmentScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/white" android:orientation="vertical"> <RelativeLayout android:layout_width="match_parent" android:layout_height="360dp"> <android.support.v4.view.ViewPager android:id="@+id/fragment_viewpager" android:layout_width="match_parent" android:layout_height="wrap_content" /> <LinearLayout android:id="@+id/fragment_dot" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignBottom="@id/fragment_viewpager" android:layout_marginBottom="10dp" android:gravity="center_horizontal" android:orientation="horizontal" /> </RelativeLayout>
。。。。。。。。。
</com.vip.group.widget.VideoFragmentScrollView>
2.解决方法,VideoFragmentScrollView里的代码:
public class VideoFragmentScrollView extends ScrollView { public VideoFragmentScrollView(Context context) { super(context); } public VideoFragmentScrollView(Context context, AttributeSet attrs) { super(context, attrs); } public VideoFragmentScrollView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } //方法二,这个方法比较死板,不太灵活,虽然能满足基本需求,副作用很大 @Override protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) { return true; } // /** // * 方法三,方法二类似 // * 解决ScrollView中镶嵌EditViewiew和GridView、ListView等刷新时EditViewiew不展示的问题 // */ // @Override // protected int computeScrollDeltaToGetChildRectOnScreen(Rect rect) { // return 0; // } }
3.解决ScrollView自动滑到底部、中间或listView的头部的问题
// //解决scrollView就会自动滑到底部或者中间部分的问题 // listDetails.setFocusable(false); // listAssess.setFocusable(false); // listStock.setFocusable(false); // listPeer.setFocusable(false);