记录VideoView在小米Android系统4.4上被ScrollView嵌套时,滑动后下面的界面变黑色解决事件(高系统版本没有这种问题)

本文解决了Android中VideoView导致ScrollView滑动异常的问题,通过嵌套布局和调整控件数量,确保了滚动流畅且视频正常显示。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

首先贴出会出现滑动后变黑色的XML文件

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true"
    android:fadingEdge="none"
    android:scrollbars="none">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <RelativeLayout
            android:id="@+id/video_act_relative"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            tools:context=".ui.VideoActivity">


                <VideoView
                    android:id="@+id/video_act_video_view"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="0dp"
                    android:layout_marginLeft="0dp"
                    android:layout_marginTop="0dp"
                    android:layout_marginEnd="0dp"
                    android:layout_marginRight="0dp"
                    android:layout_marginBottom="0dp" />



            <ImageView
                android:id="@+id/video_act_back"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="16dp"
                android:layout_marginLeft="16dp"
                android:layout_marginTop="16dp"
                app:srcCompat="@drawable/icon_back"
                tools:ignore="ContentDescription"
                tools:layout_editor_absoluteX="16dp"
                tools:layout_editor_absoluteY="16dp" />

            <ImageView
                android:id="@+id/video_act_like"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignBottom="@id/video_act_back"
                android:layout_marginStart="24dp"
                android:layout_marginLeft="24dp"
                android:layout_marginBottom="2dp"
                android:layout_toEndOf="@id/video_act_back"
                android:layout_toRightOf="@id/video_act_back"
                app:srcCompat="@drawable/icon_un_like"
                tools:ignore="ContentDescription"
                tools:layout_editor_absoluteX="64dp"
                tools:layout_editor_absoluteY="18dp" />

            <ImageView
                android:id="@+id/video_act_report"
                android:layout_width="22dp"
                android:layout_height="22dp"
                android:layout_alignBottom="@id/video_act_like"
                android:layout_marginStart="24dp"
                android:layout_marginLeft="24dp"
                android:layout_toEndOf="@id/video_act_like"
                android:layout_toRightOf="@id/video_act_like"
                app:srcCompat="@drawable/icon_report"
                tools:ignore="ContentDescription"
                tools:layout_editor_absoluteX="108dp"
                tools:layout_editor_absoluteY="17dp" />

            <ImageView
                android:id="@+id/video_act_edit"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_alignBottom="@id/video_act_report"
                android:layout_marginStart="24dp"
                android:layout_marginLeft="24dp"
                android:layout_toEndOf="@+id/video_act_report"
                android:layout_toRightOf="@+id/video_act_report"
                app:srcCompat="@drawable/icon_share"
                tools:ignore="ContentDescription"
                tools:layout_editor_absoluteX="154dp"
                tools:layout_editor_absoluteY="18dp" />

            <TextView
                android:id="@+id/video_act_attention"
                android:layout_width="105dp"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:background="@drawable/attention_shape"
                android:drawableStart="@drawable/icon_add"
                android:drawableLeft="@drawable/icon_add"
                android:drawablePadding="2dp"
                android:paddingStart="12dp"
                android:paddingLeft="12dp"
                android:text="关注"
                android:textColor="@color/white"
                android:textSize="15sp"
                tools:ignore="RtlSymmetry"
                tools:layout_editor_absoluteX="263dp"
                tools:layout_editor_absoluteY="16dp" />

            <de.hdodenhof.circleimageview.CircleImageView
                android:id="@+id/video_act_user_head"
                android:layout_width="33dp"
                android:layout_height="33dp"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_marginTop="16dp"
                android:layout_marginEnd="16dp"
                android:layout_marginRight="16dp"
                android:src="@drawable/icon_head"
                tools:layout_editor_absoluteX="335dp"
                tools:layout_editor_absoluteY="16dp" />

        </RelativeLayout>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />


    </LinearLayout>


</ScrollView>

问了同事说,出现该事件是因为VideoView 覆盖了ScrollView,只要在VideoView嵌套一个布局就行了,于是我套了一个线性布局,果然!可以了!

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <VideoView
                    android:id="@+id/video_act_video_view"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginStart="0dp"
                    android:layout_marginLeft="0dp"
                    android:layout_marginTop="0dp"
                    android:layout_marginEnd="0dp"
                    android:layout_marginRight="0dp"
                    android:layout_marginBottom="0dp" />


            </LinearLayout>

 就在第二天又遇了一个坑:ScrollView在超过某个高度时候VideoView会“折叠”起来,把多余控件删除即可(因为我用了很多Button撑起了布局才能滚动,发现Button给太多超过ScrollView的某个阈值了)

虽然这是一件小事,但这开启了我人生第一次写博客,希望能保持良好的记录习惯,希望和论坛上的大神学习,共勉~ 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值