gpt4 book ai didi

安卓 : Text disappears frequently in webview when LAYER_TYPE_SOFTWARE is set

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:11:34 25 4
gpt4 key购买 nike

我正在尝试在 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>

当我在我的手机上而不是在模拟器上安装 .apk 文件时会出现此问题。我正在使用 android 版本 4.1.2。谁能告诉我需要做什么才能使显示的文本没有闪烁效果并具有透明背景?

最佳答案

请将#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>

关于安卓 : Text disappears frequently in webview when LAYER_TYPE_SOFTWARE is set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18448862/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com