1

I don't really know how to word this correctly hence me asking this question. If anyone could point me to resources that explain this that would be wonderful.

I have an android activity that I have used up all the space on. I want to be able to add items at the bottom of this activity and users can scroll down to see. For example like a web page, there is more content when you scroll down. How can I do this on android studio?

thanks.

my XML file:

      <?xml version="1.0" encoding="utf-8"?>
    <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="match_parent"
tools:context="com.example.john.myTestApp.MenuController">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

  <TextView
    android:id="@+id/venueName"
    android:layout_width="0dp"
    android:layout_height="75dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:gravity="center"
    android:text="TextView"
    android:textSize="30sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/venueImage" />

<ImageView
    android:id="@+id/venueImage"
    android:layout_width="0dp"
    android:layout_height="265dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="20dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.437"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
    app:srcCompat="@drawable/common_google_signin_btn_icon_dark" />

<TextView
    android:id="@+id/addressTextView"
    android:layout_width="374dp"
    android:layout_height="65dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:gravity="center"
    android:text="TextView"
    android:textSize="20sp"
    app:layout_constraintEnd_toStartOf="@+id/phoneNumberTextView"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/venueName" />

<TextView
    android:id="@+id/phoneNumberTextView"
    android:layout_width="273dp"
    android:layout_height="66dp"
    android:layout_marginEnd="72dp"
    android:layout_marginStart="106dp"
    android:gravity="center"
    android:text="TextView"
    android:textSize="20sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/addressTextView"
    app:layout_constraintTop_toBottomOf="@+id/venueName" />

<TextView
    android:id="@+id/urlTextView"
    android:layout_width="0dp"
    android:layout_height="72dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:gravity="center"
    android:text="TextView"
    android:textSize="20sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.497"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/phoneNumberTextView" />

<TextView
    android:id="@+id/ammenititesTextView"
    android:layout_width="0dp"
    android:layout_height="58dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:gravity="center"
    android:text="TextView"
    android:textSize="20sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/openingClosingTextView" />

<TextView
    android:id="@+id/openingClosingTextView"
    android:layout_width="0dp"
    android:layout_height="64dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:gravity="center"
    android:text="TextView"
    android:textSize="20sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/urlTextView" />

<TextView
    android:id="@+id/textView2"
    android:layout_width="0dp"
    android:layout_height="53dp"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="13dp"
    android:gravity="center"
    android:text="Fixtures"
    android:textColor="@android:color/black"
    android:textSize="20sp"
    android:textStyle="normal"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/viewMapbtn" />

<ListView
    android:id="@+id/venueFixtureListVIew"
    android:layout_width="587dp"
    android:layout_height="235dp"
    android:layout_marginEnd="110dp"
    android:layout_marginStart="110dp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textView2" />

<Button
    android:id="@+id/viewMapbtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="153dp"
    android:layout_marginStart="104dp"
    android:layout_marginTop="12dp"
    android:text="View on Map"
    app:layout_constraintEnd_toStartOf="@+id/getDirectionsBtn"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/ammenititesTextView" />

<Button
    android:id="@+id/getDirectionsBtn"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginEnd="93dp"
    android:layout_marginStart="153dp"
    android:layout_marginTop="12dp"
    android:text="Get Directions"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toEndOf="@+id/viewMapbtn"
    app:layout_constraintTop_toBottomOf="@+id/ammenititesTextView" />

<android.support.v7.widget.Toolbar
    android:id="@+id/my_toolbar"
    android:layout_width="match_parent"
    android:layout_height="64dp"
    android:background="?attr/colorPrimary"
    android:elevation="4dp"
    android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="1.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

    </android.support.constraint.ConstraintLayout>


     </ScrollView>
Phantômaxx
  • 36,442
  • 21
  • 78
  • 108

2 Answers2

1

Below Code is Show how to use scrollview in Starting and Ending in between u can use your TextView, EditText anything u want

<?xml version="1.0" encoding="utf-8"?>
<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:scrollbars="none"
    >

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

     //ADD HEAR LIKE EditText TextView anything  
 </LinearLayout>
Ali
  • 3,066
  • 4
  • 15
  • 46
  • Are you sure the height of the LinearLayout should be match_parent? I guess I'd try wrap_content. –  Mar 29 '18 at 10:12
  • 1
    ya You can take wrap_content but this is my example and i'll take a lots off LinearLayout so this is My mistake i'll change it :) Thanks @Thomas – Ali Mar 29 '18 at 10:14
  • I have implemented what you suggested, thank you. How would you set up the constraints of these textviews and widgets in the scroll view? – LogitechNumberOne Mar 29 '18 at 10:16
  • In **`LinearLayout`** you can add your **Widgets** – Ali Mar 29 '18 at 10:18
  • this is Useful then mark as a answer for other Users and if not tell me what the issue @LogitechNumberOne – Ali Apr 03 '18 at 09:02
0

It depends if the content of your Activity is static or dynamic. By static I mean that you have a layout file (xyz.xml) that is shown via setContentView(R.layout.xyz). If this is the case just put your root view group inside a <ScrollView ... />

If you have dynamic content, it depends if this is list-like data. If so, use either <ListView /> or <RecyclerView />. For other types of data is suggest <LinearLayout /> and adding content from code.

  • My layout is static but it is a constraints layout. – LogitechNumberOne Mar 29 '18 at 10:18
  • You can wrap your ConstraintsLayout in a ScrollView. See this answer: https://stackoverflow.com/a/37545728/5956451 There once was a bug preventing this, but it has been fixed. –  Mar 29 '18 at 10:27