How to use ScrollView in Android?
Just make the top-level layout a ScrollView:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<TableLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:stretchColumns="1">
<!-- everything you already have -->
</TableLayout>
</ScrollView>
How to use ScrollView inside a RecyclerView in android Studio
You can't add ScrollView inside a TextView. Instead you can apply scrolling feature to a TextView. To apply scrolling behaviour do the following.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hyderabad"
android:id="@+id/sample"
android:layout_gravity="right"
android:textSize="30sp"
android:maxLines="40"
android:scrollbars="vertical"/>
In Java code use the following
TextView tv = (TextView)findViewById(R.id.sample);
tv.setText("Long long ..................add more text here........text");
tv.setMovementMethod(new ScrollingMovementMethod());
how to use scrollview in layout with toolbar and bottomnavigationview?
- There needs to be only one layout inside
ScrollView
. - You do not need to put
ScrollView
insideScrollView
.
You have added the include tag inside theScrollView
and your
design.xml also hasScrollView
. - I would not use android:fillViewport tag inside ScrollView, instead
use properties related to relative layout.
Rest of the things don't seem too difficult to figure out.
Using a ScrollView to Design a Registration Activity
I assume you do want the back
button to navigate back to some other screen from the Registration
screen? In case there are multiple fragments already that you use with your activity then you can use a ScrollView
inside that fragment. However if this is only something like a demo app where you need to add those fields inside activity directly and show a demo of the UI
of this Registration
screen only to someone, then you might consider just adding a ScrollView
in your activity and putting all the Views
inside it.
Is it possible to put a ConstraintLayout inside a ScrollView?
There was a bug with ConstraintLayout inside ScrollViews and it has been fixed. google has fixed the bug in Android Studio 2.2 Preview 2 (constraintlayout 1.0.0-alpha2).
Check this link for new update (Preview 2): works properly inside ScrollView and RecycleView
Solution 1:
The solution was to use
android:fillViewport="true"
on theScrollView
Solution 2:
Use
NestedScrollView
instead ofScrollView
withandroid:fillViewport="true"
Edit - 09/16/20:
Currently, it is more usual to use the ScrollView with the ConstraintLayout height set to wrap_content, it works very well, don't forget the fillViewPort and that both Scroll and Nested support only one direct child.
Android list view inside a scroll view
For any Child view to scroll inside a ScrollView. Anything like ListView, RecyclerView, etc. You just have to replace ScrollView with androidx.core.widget.NestedScrollView in your current xml and then magic happens.
Below is a sample xml code :
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
android:paddingBottom="20dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Recycler View inside a Scroll View"
android:textColor="@color/black"
android:textSize="@dimen/_20sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="Below is a Recycler View as an example."
android:textSize="16sp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@id/et_damaged_qty" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:text="This textview automatically goes below the Recycler View."
android:textSize="16sp" />
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.core.widget.NestedScrollView>
Now you can get rid of all the ugly hacks you did to get around with nested scrolling.
Related Topics
How to Create a Closed (Circular) Listview
Runtimeexception: Unable to Instantiate Application
How to Make My App a Device Owner
Finished with Non Zero Exit Value
How to Start Activity in Another Application
Put Constant Text Inside Edittext Which Should Be Non-Editable - Android
How to Get Onclick Event on Webview in Android
How to Sign an Android APK File
How to Get Resource Name from Resource Id
Android - Listview Get Item View by Position
How to Modify Arrayadapter in Listview: Unsupportedoperationexception
How to Disable Gradle 'Offline Mode' in Android Studio
How to Set My App as the Default Sms App
Passing Image from One Activity Another Activity
Telephonymanager.Getline1Number() Failing