所以我有一个有趣的问题。尽管我没有手动或以编程方式滚动视图,但在加载WebView中的数据后,它会自动滚动到该视图。
我在取景器里找到了一个碎片。当我第一次加载寻呼机时,它按预期工作,所有内容都会显示出来。但是,一旦我“翻转页面”,数据加载和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。我如何防止这种情况发生?
发布于 2013-10-02 17:23:10
您可以简单地将其添加到您的LinearLayout: android:focusableInTouchMode="true“中。这对我很管用。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusableInTouchMode="true"
android:orientation="vertical" >
发布于 2013-02-01 02:17:33
我也遇到了同样的问题,经过几个小时的尝试,最终对我起作用的是简单地将descendantFocusability
属性添加到ScrollView的包含LinearLayout的值为blocksDescendants
的ScrollView中。在您的案例中:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >
从那以后,这个问题就再也没有发生过。
发布于 2012-07-02 14:02:21
您应该创建新的类来扩展ScrollView,然后覆盖requestChildFocus:
public class MyScrollView extends ScrollView {
@Override
public void requestChildFocus(View child, View focused) {
if (focused instanceof WebView )
return;
super.requestChildFocus(child, focused);
}
}
然后在您的xml布局中,使用:
<MyScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/background" >
这对我很有效。ScrollView将不再自动滚动到WebView。
https://stackoverflow.com/questions/9842494
复制相似问题