当我在 android webview 中加载 YouTube 视频 url 时,我有点挣扎。我将该特定 YouTube 视频链接的嵌入代码加载到 web 视图中。我成功加载了。这里我的问题是,我必须加载超过 10 个链接,所以我使用滚动视图(我也使用列表视图)来显示加载的链接。当我滚动它放置在标题布局上的布局时,它也没有正确加载。在这里,我将我的代码与我的输出屏幕截图一起发布,请任何人帮助我解决这个问题。提前致谢。
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<include
android:id="@+id/header"
layout="@layout/header_layout" />
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="@+id/header"
android:orientation="vertical"
android:scrollbars="none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="2dp" >
<!-- <ImageView -->
<!-- android:id="@+id/inner_image" -->
<!-- android:layout_width="fill_parent" -->
<!-- android:layout_height="wrap_content" -->
<!-- android:layout_below="@+id/inner_image" -->
<!-- android:background="@drawable/lyrics_inner" /> -->
<WebView
android:id="@+id/web"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<WebView
android:id="@+id/web1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/web" />
<WebView
android:id="@+id/web2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/web1" />
<WebView
android:id="@+id/web3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/web2" />
<WebView
android:id="@+id/web4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/web3" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
header_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/header_backButton"
android:layout_width="fill_parent"
android:layout_height="60dp"
android:background="#333322"
android:gravity="center_horizontal"
android:text="HOME"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="#FFFFFF"
/>
YoutubeActivity.java
package com.devappandroid.youtube;
import android.app.Activity;
import android.os.Bundle;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
public class YoutubeActivity extends Activity {
/** Called when the activity is first created. */
private String src_value = "http://www.youtube.com/v/9WFvopZMty4?version=3&feature=player_embedded";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.main);
WebView myWebView = (WebView) findViewById(R.id.web);
WebView myWebView1 = (WebView) findViewById(R.id.web1);
WebView myWebView2 = (WebView) findViewById(R.id.web2);
WebView myWebView3 = (WebView) findViewById(R.id.web3);
WebView myWebView4 = (WebView) findViewById(R.id.web4);
myWebView.getSettings().setPluginState(WebSettings.PluginState.ON);
myWebView1.getSettings().setJavaScriptEnabled(true);
myWebView1.getSettings()
.setJavaScriptCanOpenWindowsAutomatically(false);
myWebView1.getSettings().setPluginsEnabled(true);
myWebView1.getSettings().setSupportMultipleWindows(false);
myWebView1.getSettings().setSupportZoom(false);
myWebView1.setVerticalScrollBarEnabled(false);
myWebView1.setHorizontalScrollBarEnabled(false);
myWebView2.getSettings().setJavaScriptEnabled(true);
myWebView2.getSettings()
.setJavaScriptCanOpenWindowsAutomatically(false);
myWebView2.getSettings().setPluginsEnabled(true);
myWebView2.getSettings().setSupportMultipleWindows(false);
myWebView2.getSettings().setSupportZoom(false);
myWebView2.setVerticalScrollBarEnabled(false);
myWebView2.setHorizontalScrollBarEnabled(false);
myWebView3.getSettings().setJavaScriptEnabled(true);
myWebView3.getSettings()
.setJavaScriptCanOpenWindowsAutomatically(false);
myWebView3.getSettings().setPluginsEnabled(true);
myWebView3.getSettings().setSupportMultipleWindows(false);
myWebView3.getSettings().setSupportZoom(false);
myWebView3.setVerticalScrollBarEnabled(false);
myWebView3.setHorizontalScrollBarEnabled(false);
myWebView4.getSettings().setJavaScriptEnabled(true);
myWebView4.getSettings()
.setJavaScriptCanOpenWindowsAutomatically(false);
myWebView4.getSettings().setPluginsEnabled(true);
myWebView4.getSettings().setSupportMultipleWindows(false);
myWebView4.getSettings().setSupportZoom(false);
myWebView4.setVerticalScrollBarEnabled(false);
myWebView4.setHorizontalScrollBarEnabled(false);
String newPlay = "<object style=\"height: 250px; width: 250px\"><param name=\"movie\" value="
+ src_value
+ "\"><param name=\"allowFullScreen\" value=\"true\"><param name=\"allowScriptAccess\" value=\"always\"><embed src="
+ src_value
+ " type=\"application/x-shockwave-flash\" allowfullscreen=\"true\" allowScriptAccess=\"always\" width=\"360\" height=\"360\"></object >";
myWebView.loadData(newPlay, "text/html", "utf-8");
myWebView1.loadData(newPlay, "text/html", "utf-8");
myWebView2.loadData(newPlay, "text/html", "utf-8");
myWebView3.loadData(newPlay, "text/html", "utf-8");
myWebView4.loadData(newPlay, "text/html", "utf-8");
}
}
输出截图: