1
當我在android webview中加載YouTube視頻網址時,我有點掙扎。我將該特定YouTube視頻鏈接的嵌入代碼加載到網絡視圖中。我成功加載。這裏我的問題是,我必須加載超過10個鏈接,所以我使用scrollview(我也使用listview)來顯示加載的鏈接。當我滾動的佈局,它放置在頁眉佈局,也沒有正確加載。在這裏我發佈我的代碼與我的輸出截圖任何一個請幫我解決這個問題。提前致謝。android webview將無法正常工作
main.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");
}
}
輸出截圖:
感謝您的答覆,不幸的是它不會工作,它remaing相同 – Aerrow 2012-04-27 11:26:00
@Aerrow顯示我的編輯注) – 2012-04-27 11:50:51
我改變了我的佈局按照您的代碼。這個問題不會清楚 – Aerrow 2012-04-27 12:00:20