0

I am new to Android. I am creating a form to add users. As the form fields are many, I need to scroll down. I read that the ScrollView takes only one child view. I have wrapped my view inside a Linear Layout which is the direct child of the ScrollView.

<ScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:background="@color/colorWhite" android:animateLayoutChanges="true" android:scrollbars="none"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <EditText... /> <EditText.../> <EditText... /> <EditText.../> <LinearLayout... > <LinearLayout... > <LinearLayout... > <TextView... /> </LinearLayout> <ScrollView/> 
1
  • whether your issue solved? Commented Oct 22, 2018 at 7:02

3 Answers 3

1

Use below code

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:fillViewport="true" android:layout_marginTop="30dp" android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/scrollView"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 1" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 2" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 3" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 4" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 5" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 6" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 7" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 8" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 9" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 10" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 11" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 12" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 13" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 14" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 15" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 16" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 17" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 18" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 19" /> <Button android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Button 20" /> </LinearLayout> </ScrollView> 
Sign up to request clarification or add additional context in comments.

Comments

1

Change the xml of your scrollview to this

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> 

Comments

1

You need to add some attributes:

1) To your ScrollView:

android:fillViewport="true" 

2) And to your LinearLayout:

android:descendantFocusability="blocksDescendants" 

Example:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/cardDetailScrollView" android:layout_width="match_parent" android:layout_height="match_parent" android:fillViewport="true"> <LinearLayout android:id="@+id/card_detail_linear_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:descendantFocusability="blocksDescendants"> Your Content... </LinearLayout> </ScrollView> 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.