Scroll view doesn't work with constraint layout all the content wrap up in my phone screen. Should i use scrollview as a parent layout ?What should be the width of my ScrollView Layout, i am confused with wrap_content and match_parent.............................................................................. This is what i am getting
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
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="match_parent"
android:background="#1a1a22"
tools:context="com.example.mrfrag.fullchargealarm.Settings">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/scrollView6" android:fillViewport="true"
android:layout_marginTop="8dp"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginEnd="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="8dp"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:scrollbars = "vertical"
android:scrollbarStyle="insideInset"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintVertical_bias="0.0">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FIRE1" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textVie2321"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textVie23"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textVie45"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/tesadasdxtVie3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/teasasdxtVie3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/texasastVie3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/textasdasdVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/tasdasdextVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/texastVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/texVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
<TextView
android:id="@+id/tetVsase3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textColor="#ffffff"
android:text="FFIRE" />
</LinearLayout>
</ScrollView>
</android.support.constraint.ConstraintLayout>
To get it to work, make the ScrollView the parent view, with width and height of match_parent
(so it fills the screen). Then put the next layout inside it with a width of match_parent
(so it's the width of the parent) and a height of wrap_content
(so it can be taller than the parent height and scrolls to show the content).
What does wrap_content
do? It lets the view be as tall as needed to display its content. If it's taller than the parent then the ScrollView
lets you scroll up and down to see the content.
For example:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- this could be a constraint layout instead if you want -->
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- STUFF -->
</LinearLayout>
</ScrollView>
In your case the parent ConstraintLayout isn't necessary since there's only one subview and it's filling the parent view, but if you wanted to keep the heirarchy you have, just change the LinearLayout
immediately inside the ScrollView
to a height of wrap_content