Android ScrollView自动滚动到视图底部 [英] Android ScrollView automatically scrolls to the bottom of the view

查看:65
本文介绍了Android ScrollView自动滚动到视图底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个活动,其中包含一个地图,图像和另一个文本视图,并且为此添加了"scrollview"标签.但是活动开始后,它将自动滚动到页面末尾.请告诉我为什么会发生这种情况,以及如何阻止这种情况持续下去,以便我自己滚动一下.

I have created one activity which is containing one map, image and another text view, and I have added "scrollview" tag for it. But after the activity starts it scrolls to the end of the page automatically. Please tell me why this happens and how to stop it from moving to end so I can scroll it by myself.

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

推荐答案

我也曾经遇到过相同的情况,但是将DescendantFocusability属性添加到包含ScrollView的LinearLayout中,解决了我的问题.

I also face the same scenario once but adding the descendantFocusability attribute to the ScrollView's containing LinearLayout, solve my issue.

android:descendantFocusability="blocksDescendants"

您可以将其用作:

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

这篇关于Android ScrollView自动滚动到视图底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆