Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/235.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:设置LAYER_TYPE_软件时,文本在webview中经常消失_Android_Android Webview - Fatal编程技术网

Android:设置LAYER_TYPE_软件时,文本在webview中经常消失

Android:设置LAYER_TYPE_软件时,文本在webview中经常消失,android,android-webview,Android,Android Webview,我试图在scrollview中添加一个webview,它可以显示带有透明背景的静态HTML文本。这是密码 WebView descr = (WebView) view.findViewById(R.id.description); descr.setBackgroundColor(Color.TRANSPARENT); descr.loadData(desc, "text/html", "utf-8"); descr.setLaye

我试图在scrollview中添加一个webview,它可以显示带有透明背景的静态HTML文本。这是密码

        WebView descr = (WebView) view.findViewById(R.id.description);
        descr.setBackgroundColor(Color.TRANSPARENT);
        descr.loadData(desc, "text/html", "utf-8");
        descr.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
如果未设置setLayerType值,则可以正确查看文本。但是,当滚动完成时,它会增加闪烁效果。如果添加了setLayerType行,则某些页面的文本将消失。下面是我的布局

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/title" >

    <LinearLayout 
        android:orientation="vertical" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:descendantFocusability="blocksDescendants">

        <ImageView
            android:id="@+id/icon"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:contentDescription="@id/title"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            />

        <WebView
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:textAlignment="gravity"
            android:textSize="14sp"
            android:background="@null"
            android:focusable="false" />
    </LinearLayout>
</ScrollView>


当我在手机上而不是emulator上安装.apk文件时,就会出现此问题。我使用的是android版本4.1.2。有人能告诉我需要做些什么,以便文本显示时不会出现闪烁效果,背景透明吗?

我遇到了同样的问题,我解决了这个问题;scrollview中的webview和webview的setlayertype软件,所以scrollview需要setlayertype软件;如下图所示:

<ScrollView
    android:layout_width="match_parent"
    android:layerType="software"
    android:layout_height="match_parent"
    android:layout_below="@+id/title" >

我希望这能对您有所帮助。

请将#android:layerType=“software”#添加到WebView和ScrollView之前的所有容器中。在Android4.4上,它适合我

<ScrollView
    android:layerType="software"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/title" >

    <LinearLayout 
        android:layerType="software"
        android:orientation="vertical" 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:descendantFocusability="blocksDescendants">

        <ImageView
            android:id="@+id/icon"
            android:layout_width="fill_parent"
            android:layout_height="100dp"
            android:contentDescription="@id/title"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            />

        <WebView
            android:layerType="software"
            android:id="@+id/description"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp"
            android:paddingTop="10dp"
            android:textAlignment="gravity"
            android:textSize="14sp"
            android:background="@null"
            android:focusable="false" />
    </LinearLayout>
</ScrollView>

我也有同样的问题,但情况正好相反;当点击文本输入框并向上滚动软键盘(在我的索尼手机上)时,webview中的内容消失了

以下是我使用的对webview有直接影响的所有设置:

  • 在清单中,在活动声明中,要在键盘向上滚动时使webview平移,请执行以下操作:
    android:windowSoftInputMode=“adjustPan”
  • 在布局的根目录中,允许Web视图在键盘向上滚动时平移:
    android:fitsystemwindows=“true”
  • 在webview中,要禁用硬件加速以防止网页表单项在键盘向上滚动时消失:
    android:layerType=“software”

我也面临同样的问题,您是否找到了解决方案。如果是,请共享itI更改了与TextView的webview。我通过实现Html.TagHandler对文本进行格式化。这似乎是一个不常见的问题。我不确定它是特定于设备还是特定于android版本。我想我是唯一一个面临这个问题的人,这一定是我的设备的问题。但是,由于您面临相同的问题,我已在上报告了相同的问题。请让我知道您使用的设备。不需要scrollview,因为webview可以自动滚动