سؤال

لقد ضاقت المشكلة في WebView ؛ قوة طلبي تغلق في كل مرة. إذا أخرجت WebView ووضعت في زر تغيير اللون أو شيء ما ، فإن تبديل الحالة يعمل وتحميل التطبيق. أنا جديد إلى حد ما على PLAForm ، لكنني (في الغالب) نسخ مباشرة من أمثلة هنا لمشاهدات الويب.

application.java

package com.xxxx.xxxxx;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;

public class Application extends Activity {

  @Override
  public void onCreate(Bundle icicle) {

    super.onCreate(icicle);
    setContentView(R.layout.main);

  }

  public void myClickHandler(View view) {

   WebView engine = (WebView) findViewById(R.id.webview);
   switch (view.getId()) {

       case R.id.Button1:
        engine.loadUrl("http://digg.com");
        break;

       case R.id.Button2:
        engine.loadUrl("http://reddit.com");
        break;

    }

     }

} 

main.xml

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:id="@+id/ScrollParent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"> 

 <LinearLayout android:id="@+id/MainMenuLayout"
  android:layout_width="310px"
   android:layout_height="fill_parent"
   android:orientation="vertical">

   <TextView 
    android:id="@+id/Application"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Application Name..." />

   <Button android:id="@+id/Button1"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="Digg"
         android:onClick="myClickHandler"/>

        <Button android:id="@+id/Button2"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="Reddit"
         android:onClick="myClickHandler"/>

 </LinearLayout>

 <LinearLayout  
  android:orientation="vertical"  
  android:layout_width="fill_parent"  
  android:layout_height="fill_parent"  >  

     <WebView
      android:id="@+id/webview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>

 </LinearLayout>
</ScrollView>

Androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.qxmd.ecgguide"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-permission android:name="android.permission.INTERNET" />

    <application android:icon="@drawable/icon" android:label="@string/app_name">
        <activity android:name=".Application"
                  android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

    </application>


</manifest> 
هل كانت مفيدة؟

المحلول

جذر التخطيط الخاص بك هو scrollview مع اثنين من العقد طفل. Scrollview يدعم فقط عقدة طفل واحد. إذا نظرت إلى سجل ADB ، فإن الاستثناء الذي يتم طرحه عندما يخبرك التطبيق الخاص بك هذا:

Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child

يتمثل أحد الحلول الممكنة في إنشاء تصميم واحد يديره ScrollView ، وجعل اثنين من linearlayouts موجودان أن يكونا أطفالًا في التصميم الجديد. إليك تعديل مباشر لـ Main.xml الأصلي:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView
    android:id="@+id/ScrollParent"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">

<!-- new container layout for the original two layouts -->
<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

 <!-- original first child layout, now a child of the wrapper -->
 <LinearLayout android:id="@+id/MainMenuLayout"
  android:layout_width="310px"
   android:layout_height="fill_parent"
   android:orientation="vertical">

   <TextView 
    android:id="@+id/Application"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:text="Application Name..." />

   <Button android:id="@+id/Button1"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="Digg"
         android:onClick="myClickHandler"/>

        <Button android:id="@+id/Button2"
         android:layout_width="fill_parent"
         android:layout_height="wrap_content"
         android:text="Reddit"
         android:onClick="myClickHandler"/>

 </LinearLayout>

 <!-- the original second child layout, now also a child of the wrapper -->
 <LinearLayout  
  android:orientation="vertical"  
  android:layout_width="fill_parent"  
  android:layout_height="fill_parent"  >  

     <WebView
      android:id="@+id/webview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"/>

 </LinearLayout>

</LinearLayout>
</ScrollView>
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top