当我在Android webview中加载YouTube视频网址时,我有点挣扎。我将该特定YouTube视频链接的嵌入代码加载到webview中。我成功装了。这里我的问题是,我必须加载超过10个链接,所以我使用scrollview(我也使用listview)来显示加载的链接。当我滚动它放置在标题布局上的布局时,它也没有正确加载。在这里,我用我的输出截图发布我的代码任何一个请帮我解决这个问题。提前谢谢。
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");
}
}
输出截图:
答案 0 :(得分:1)
而RelativeLayout使用LinearLayout(垂直视图)。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/header_backButton"
android:layout_width="fill_parent"
android:layout_height="60dip"
android:background="#333322"
android:gravity="center_horizontal"
android:text="HOME"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="#FFFFFF"
/>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/header"
android:scrollbars="none" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="2dip" >
<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" />
</LinearLayout>
</ScrollView>
</LinearLayout>