Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android ScrollView automatically scrolls to the bottom of the view

Tags:

android

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> 

like image 396
Debasmita Chakraborty Avatar asked Jan 20 '16 12:01

Debasmita Chakraborty


People also ask

Is it possible to keep a ScrollView scrolled to the bottom?

To keep a ScrollView scrolled to the bottom with React Native, we can assign a ref to the ScrollView and call scrollToEnd on it.

How do I scroll to the bottom of the page on Android?

Open a webpage in a browser on your Android device. Make sure the webpage is long enough so that the browser shows a scroll bar. Once there, to get to the bottom of the page, simply tap the top right corner on your device. In the screenshot below, I need to tap the area where the time is shown.

Can scroll vertically Android?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.


1 Answers

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

android:descendantFocusability="blocksDescendants" 

you can use this as :

<LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:descendantFocusability="blocksDescendants" > 
like image 132
Punit Sharma Avatar answered Oct 04 '22 06:10

Punit Sharma