【问题标题】:Android:Webview within Scrollview is not working properlyAndroid:Scrollview 中的Webview 无法正常工作
【发布时间】:2016-03-03 06:29:38
【问题描述】:

我正在尝试通过将 webview 嵌入到 android 的相对布局的滚动视图中来创建富文本编辑器。 webview 显示一个带有可编辑 div 的 html 文件。

<html>

<body>
<div id="editor"  contentEditable="true"></div>
</body>
</html>

布局文件:-

 <ScrollView
    android:id="@+id/blog_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="30dp"
    android:clipToPadding="false"
    android:layout_above="@+id/Footer"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
   >
    <RelativeLayout
        android:id="@+id/rlContent"
        android:layout_width="match_parent"
        android:layout_height="200px">
      <com.medicodesk.ionapp.utils.editor.RichEditor
          android:id="@+id/editor"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          />
    </RelativeLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/Footer"
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:orientation="horizontal"
    android:layout_alignParentBottom="true"
    android:visibility="invisible">

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/black"
    android:layout_above="@+id/blog_content"
    android:id="@+id/blog_editor_toolbar"
    >

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        >

        <ImageButton
            android:id="@+id/action_undo"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:background="@null"
            android:contentDescription="@null"
            android:src="@drawable/undo"
            />



        <ImageButton
            android:id="@+id/action_blockquote"
            android:layout_width="48dp"
            android:layout_height="48dp"
            android:background="@null"
            android:contentDescription="@null"
            android:src="@drawable/blockquote"
            />


    </LinearLayout>
</HorizontalScrollView>
</LinearLayout>

RichEditor 布局是 weblayout 子布局,通过调用 javascript 与 html 交互。

问题是我无法将编辑器窗口高度设置为适合 android 移动布局大小。编辑器将处于显示模式,显示用户输入的所有内容,或者将处于键盘布局从底部弹出的编辑模式。编辑器应该只能垂直滚动。我不清楚我是否应该依靠 html 滚动或 android 滚动视图来获得平滑滚动。

请帮帮我。

【问题讨论】:

标签: android webview scrollview rich-text-editor


【解决方案1】:

尝试更改您的 XML 布局,如下所示:

<?xml version="1.0" encoding="utf-8"?>

<ScrollView
    android:id="@+id/blog_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/Footer"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:clipToPadding="false"
    android:paddingBottom="30dp">

    <RelativeLayout
        android:id="@+id/rlContent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <com.medicodesk.ionapp.utils.editor.RichEditor
            android:id="@+id/editor"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </RelativeLayout>
</ScrollView>

<LinearLayout
    android:id="@+id/Footer"
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:layout_alignParentBottom="true"
    android:orientation="horizontal"
    android:visibility="invisible">

    <HorizontalScrollView
        android:id="@+id/blog_editor_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/blog_content"
        android:background="@android:color/black">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <ImageButton
                android:id="@+id/action_undo"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@drawable/undo" />


            <ImageButton
                android:id="@+id/action_blockquote"
                android:layout_width="48dp"
                android:layout_height="48dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@drawable/blockquote" />


        </LinearLayout>
    </HorizontalScrollView>
</LinearLayout>

希望对你有帮助。

【讨论】:

  • 很抱歉造成混淆。我想使用 webview、html div 和 javascript document.exec() 命令在 android 中创建一个富文本编辑器。我的要求是显示一个仅包含可编辑文档的网页(如下所示 sn-p)
    in android 活动布局(任何布局)。活动应将网页显示为文本区域供用户输入。当用户尝试键入时,键盘会打开并且布局的大小会减小。网页应该可以根据可用大小滚动。
猜你喜欢
  • 1970-01-01
  • 2017-03-16
  • 2018-07-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多