scrollview嵌入webview导致自动滚动

来源:互联网 发布:全球生产网络弊端 编辑:程序博客网 时间:2024/06/03 20:16

当我们在界面外层使用了ScrollView,内层又有WebView时,当进入界面后,会导致ScrollView自动滚动到webView刚好可见的位置。

找了下资料,参考链接:https://stackoverflow.com/questions/9842494/how-to-prevent-a-scrollview-from-scrolling-to-a-webview-after-data-is-loaded

布局像这样:

<?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>

发现是一个聚焦的问题,加上下面这行代码就可以了:

android:descendantFocusability="blocksDescendants"
放在这个位置:

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


原创粉丝点击