1

YouTube ビデオの URL を Android の Web ビューにロードするときに少し苦労します。その特定の YouTube ビデオ リンクの埋め込みコードを webview に読み込みます。読み込みに成功しました。ここで私の問題は、10を超えるリンクをロードする必要があるため、スクロールビューを使用して(リストビューも使用しました)、ロードされたリンクを表示することです。ヘッダー レイアウトの上に配置されたレイアウトをスクロールすると、正しく読み込まれません。ここで、出力スクリーンショットを使用してコードを投稿します。この問題の解決を手伝ってください。前もって感謝します。

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");
    }
}

出力スクリーンショット: ここに画像の説明を入力

4

1 に答える 1

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>
于 2012-04-27T11:15:29.720 に答える