所以我有一个有趣的问题。尽管我没有手动或以编程方式滚动视图,但我的 WebView 会在加载其中的数据后自动滚动。
我在 viewpager 中有一个片段。当我第一次加载寻呼机时,它按预期工作并且显示所有内容。但是,一旦我“翻转页面”,数据就会加载,并且 WebView 会弹出到页面顶部,隐藏其上方的视图,这是不可取的。
有谁知道如何防止这种情况发生?
我的布局看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/article_title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="2dp"
android:text="Some Title"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="@color/article_title"
android:textStyle="bold" />
<LinearLayout
android:id="@+id/LL_Seperator"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:background="@color/text"
android:orientation="horizontal" >
</LinearLayout>
<WebView
android:id="@+id/article_content"
android:layout_width="match_parent"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/article_link"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:text="View Full Article"
android:textColor="@color/article_title"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
我也没有把注意力集中在任何事情上。默认情况下,它似乎在加载后自动滚动到 WebView。我该如何防止这种情况?
我遇到了同样的问题,经过几个小时的尝试几个想法后,最终对我有用的是简单地添加descendantFocusability
包含 LinearLayout 的 ScrollView 的属性,其值为blocksDescendants
。在你的情况下:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
从那以后就没有再出现过这个问题。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)