2

我使用XWalkView加载网页并使用IjkVideoView在我的应用程序中播放实时视频。我想让 IjkVideoView 在 XwalkView 前面播放视频,所以我把这两个视图放在一个 relativelayout 中,而 IijVideoView 放在 XWalkView 后面。

在 android studio 的 Component Tree of Design 窗口中,布局看起来没问题,如下图所示,

在此处输入图像描述

当我在我的设备中运行应用程序时,布局一团糟,如下图所示。可以看到 IjkVieoView 的背景在 XWalkView 前面,而在 IjkVideoView 中播放的视频在 XWalkView 后面,因为视频的上半部分已经被 XWalkView 覆盖了。

在此处输入图像描述

布局xml,

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:ignore="UselessParent">

        <!-- This could be your fragment container, or something -->

        <org.xwalk.core.XWalkView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/xWalkView"
            android:layout_width="fill_parent"
            android:layout_height="160dp"
            android:background="@color/blue"
            android:isScrollContainer="true">

        </org.xwalk.core.XWalkView>

        <com.xxxxxx.app.widget.media.IjkVideoView
            android:id="@+id/video_view"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="72dp"
            android:background="@color/colorAccent" />

        <com.roughike.bottombar.BottomBar
            android:id="@+id/bottomBar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:layout_alignParentBottom="true"
            app:bb_tabXmlResource="@xml/web_tabs" />

    </RelativeLayout>
</LinearLayout>

活动java代码,

protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Log.d("INFO", "entered");
        setContentView(R.layout.activity_web);
        mXWalkView = (XWalkView) findViewById(R.id.xWalkView);
        XWalkSettings webSettings = mXWalkView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mXWalkView.addJavascriptInterface(new JsInterface(), "NativeInterface");

        videoView = (IjkVideoView) findViewById(R.id.video_view);
        videoView.setAspectRatio(IRenderView.AR_ASPECT_FILL_PARENT);
        videoView.setVideoURI(Uri.parse("http://live.xxxxxx.com/live/40xx27.flv"));
        videoView.start();

        final Bundle extras = getIntent().getExtras();
        mXWalkView.load("http://xxxxxxxxxxxxxx", null);
}
4

3 回答 3

3

您的布局似乎是正确的。它可能从库中被破坏。它已经有 1k+ 个问题。

也许您可以使用包含视频的自定义对话框并显示该对话框。这样,视频将位于图像的前面。然后你可以尝试去除阴影或bgColor = transparent,这样用户可能不会意识到这是一个对话框。这个黑客可能会奏效。

于 2017-07-07T11:49:33.200 回答
1
 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:ignore="UselessParent">

        <!-- This could be your fragment container, or something -->

        <org.xwalk.core.XWalkView xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/xWalkView"
            android:layout_width="fill_parent"
            android:layout_height="160dp"
            android:background="@color/blue"
            android:elevation="5dp"
            android:isScrollContainer="true">

        </org.xwalk.core.XWalkView>

        <com.xxxxxx.app.widget.media.IjkVideoView
            android:id="@+id/video_view"
            android:layout_width="200dp"
            android:layout_height="200dp"
            android:elevation="10dp"
            android:layout_alignParentTop="true"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="72dp"
            android:background="@color/colorAccent" />

        <com.roughike.bottombar.BottomBar
            android:id="@+id/bottomBar"
            android:layout_width="match_parent"
            android:layout_height="60dp"
            android:elevation="5dp"
            android:layout_alignParentBottom="true"
            app:bb_tabXmlResource="@xml/web_tabs" />

    </RelativeLayout>
</LinearLayout>

试试这个布局,我用海拔修改它可能会对你有所帮助。我通过使用海拔来解决同样的问题。

于 2017-07-14T08:49:58.600 回答
0

我认为这是由于相对布局。您为什么不通过使用框架布局来尝试此代码。设计应用程序用户界面最方便和可维护的方法是创建 XML 布局资源。这种方法极大地简化了用户界面设计过程,将用户界面控件的大部分静态创建和布局以及控件属性的定义移至 XML,而不是乱扔代码。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    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:orientation="vertical" 
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<FrameLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" >
    <org.xwalk.core.XWalkView 
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/xWalkView"
        android:layout_width="fill_parent"
        android:layout_height="160dp"
        android:background="@color/blue"
        android:isScrollContainer="true">
    </org.xwalk.core.XWalkView>

    <com.xxxxxx.app.widget.media.IjkVideoView
        android:id="@+id/video_view"
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="72dp"
        android:layout_gravity="Bottom"
        android:gravity="center"
        android:background="@color/colorAccent" />

    <com.roughike.bottombar.BottomBar
        android:id="@+id/bottomBar"
        android:layout_width="match_parent"
        android:layout_height="60dp"
        android:layout_alignParentBottom="true"
        app:bb_tabXmlResource="@xml/web_tabs" />

       </FrameLayout>
  </LinearLayout>
于 2017-07-14T07:36:08.227 回答