首页 > 解决方案 > 有没有办法让 videoview 不是默认视图?

问题描述

这个问题可能令人困惑,所以让我概述一下。

当我通过单击按钮加载活动时,此活动首先在活动的底部加载,而不是在它应该加载的顶部。现在只是为了在我的设计中提供上下文,视频视图是“视频”部分的一部分,该部分是在活动底部加载的最后一个元素。

我尝试过一些事情,比如删除视频视图和设置不同的锚视图。但最终,到目前为止,我设法解决此问题的唯一方法是摆脱视频视图。

我将附上我在没有视频视图和视频视图的情况下看到的问题的视频。

如果有人可以提供帮助,我将不胜感激。

这是一个没有视频视图的布局链接(将此作为工作示例):

https://drive.google.com/file/d/1uhswtYUrJYnC22mlsdJzmRJqNua9mUrw/view?usp=sharing

这是带有视频视图的布局链接: https ://drive.google.com/file/d/1unHp-7GULO_TEdg6KHNjAoIOW6X-N2Rs/view?usp=sharing

我还将为添加的上下文添加视频视图部分的 XML 和 java:

XML 文件:

  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="20dp">

    <TextView
        android:id="@+id/videos"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_gravity="center"
        android:layout_marginTop="0dp"
        android:text="Videos"
        android:textAllCaps="true"
        android:textColor="#000"
        android:textSize="18sp" />
</RelativeLayout>

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="20dp">

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

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="220dp"
            android:layout_margin="8dp">

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

                <VideoView
                    android:id="@+id/videoview"
                    android:layout_width="match_parent"
                    android:layout_height="250dp"
                    android:layout_gravity="center" />
            </FrameLayout>
            
        </androidx.cardview.widget.CardView>
    </RelativeLayout>
</RelativeLayout>

Java 代码:

VideoView videoView;
private Context mContext;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.company_solo_page);
    businessesList = new ArrayList<>();
    business_name = findViewById(R.id.bus_name);
    business_logo = findViewById(R.id.profile_image);
    bdesc = findViewById(R.id.bdesc);
    website = findViewById(R.id.website);
    social = findViewById(R.id.socialmedia);
    careers = findViewById(R.id.careers);
    contact = findViewById(R.id.contact);
    videoView = findViewById(R.id.videoview);
    videoView.setVideoPath(getIntent().getStringExtra("videos"));
    videoView.start();
    MediaController mediaController = new MediaController(this);
    videoView.setMediaController(mediaController);
    mediaController.setAnchorView(videoView);

标签: javaandroidvideolayoutandroid-videoview

解决方案


使用处理程序和可运行您可以延迟执行 videoView.start() 函数调用


推荐阅读