マップ、画像、および別のテキスト ビューを 1 つ含むアクティビティを 1 つ作成し、それに「scrollview」タグを追加しました。しかし、アクティビティの開始後、自動的にページの最後までスクロールしてしまいます。なぜこのようなことが起こるのか、また、最後までスクロールしないようにして自分でスクロールできるようにする方法を教えてください。
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:orientation="vertical"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.radikallab.earch.DetailsActivity"
android:background="@drawable/background10">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:text="Title"
android:textStyle="italic"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/background4"
android:id="@+id/iv"/>
<TextView
android:id="@+id/rat"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Title"
android:textStyle="italic"/>
<TextView
android:id="@+id/addr"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="17sp"
android:text="Title"
android:textStyle="italic"/>
<WebView
android:layout_width="match_parent"
android:layout_height="500dp"
android:layout_marginTop="10dp"
android:id="@+id/webView"
android:layout_gravity="center_horizontal" />
</LinearLayout>
ベストアンサー1
私も一度同じシナリオに直面しましたが、ScrollView に含まれる LinearLayout に descendantFocusability 属性を追加すると、問題は解決しました。
android:descendantFocusability="blocksDescendants"
これを次のように使用できます:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:descendantFocusability="blocksDescendants" >