解决VideoView等视频播放控件在ViewPager使用,并嵌套在ScrollView里,视频播放时不能滚动到界面底部的问题

解决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);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值