1

I have an activity with primarily an ImageView, 3 EditText views, and a Button to save the data and send it to the database. In portrait on my device, this is typically sufficient to fit on the screen. However, I want to have scroll functionality, particularly if the device changes to a landscape view. So I've nested my constraint-layout into a ScrollView (and later a NestedScrollView a suggestion). Both views have the same behavior in this situation as far as I can tell.

What is happening in my current layout is the 'Save' button is being cut off when the device is in landscape. I've found if I add just a TextView (textView6 in the code below) with a bunch of filler text I get the desired scrolling behavior in both portrait and landscape.

How can I change my code to get the proper scrolling behavior without the filler TextView?

Edit: if I place a large blank View below the button it will at least let me scroll to the button in landscape. Is there a better way to do this?

<View
            android:layout_width="match_parent"
            android:layout_height="300dp"
            app:layout_constraintTop_toBottomOf="@id/new_request_save_button"
            app:layout_constraintLeft_toLeftOf="parent"> 

Images https://photos.app.goo.gl/vcRjaT9rGKjjH44B3

  1. Normal portrait view
  2. Landscape: won't scroll to bottom
  3. Landscape: with textView6, scrolls to bottom correctly

I've tried the suggestions I've found on these pages without success:

  • paddingBottom 10dp
  • 'stackoverflow.com/questions/38663428/android-scrollview-gets-cut-off-at-the-bottom'
  • 'stackoverflow.com/questions/11660937/android-scrollview-refuses-to-scroll-to-bottom'

XML Layout (textView6 commented out so this is the code that has the problem, with textView6 scrolls as desired.)

<?xml version="1.0" encoding="utf-8"?>

<android.support.v4.widget.NestedScrollView
    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.scaffoldtracker.NewRequestActivity"
    android:fillViewport="true"
    >

    <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >

        <android.support.v7.widget.Toolbar
            android:id="@+id/my_toolbar"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize"
            android:theme="?attr/actionBarTheme"
            android:elevation="4dp"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/new_request_photo_image_view"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:scaleType="centerCrop"
            app:layout_constraintBottom_toTopOf="@+id/guideline_40_horizontal"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:srcCompat="@drawable/ic_image_black87_24dp"
            app:layout_constraintTop_toBottomOf="@+id/my_toolbar"
            />

        <EditText
            android:id="@+id/new_request_title_edit_text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            android:ems="10"
            android:hint="@string/hint_title"
            android:inputType="textCapWords"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="@+id/guideline_40_horizontal"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp" />

        <EditText
            android:id="@+id/new_request_location_edit_text"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            android:ems="10"
            android:hint="Enter Location"
            android:inputType="textCapSentences"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/new_request_title_edit_text"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp" />

        <EditText
            android:id="@+id/new_request_description_edit_text"
            android:layout_width="0dp"
            android:layout_height="100dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            android:ems="10"
            android:gravity="top|start"
            android:hint="Enter Description"
            android:inputType="textCapSentences|textMultiLine"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/new_request_location_edit_text"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp" />


        <android.support.constraint.Guideline
            android:id="@+id/guideline_40_horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            app:layout_constraintGuide_percent="0.4"
            tools:layout_editor_absoluteY="252dp"
            tools:layout_editor_absoluteX="0dp" />

        <TextView
            android:id="@+id/new_request_click_to_upload_text_view"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="16dp"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            android:text="Click to Capture Image"
            android:textAlignment="center"
            android:textColor="@android:color/white"
            app:layout_constraintBottom_toTopOf="@+id/guideline_40_horizontal"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="@+id/new_request_photo_image_view"
            app:layout_constraintTop_toTopOf="@+id/new_request_photo_image_view"
            app:layout_constraintVertical_bias="0.39999998"
            android:layout_marginStart="16dp"
            android:layout_marginEnd="16dp" />

        <Button
            android:id="@+id/new_request_save_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="Save"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/new_request_description_edit_text" />

        <!--<TextView
            android:id="@+id/textView6"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="16dp"
            android:layout_marginRight="16dp"
            android:layout_marginTop="16dp"
            android:paddingBottom="16dp"
            android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis et pulvinar orci, sed elementum velit. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Nulla blandit, nulla vel scelerisque varius, turpis sapien pretium urna, at tempor dui eros ut odio. Pellentesque tempus tempus est, ut ultricies tellus fringilla sed. Donec sem libero, malesuada vitae libero nec, bibendum dignissim mauris. Suspendisse placerat placerat est, in imperdiet elit vehicula ac. Duis id augue est. Sed fermentum libero diam, ut suscipit nisi pulvinar et. Aenean eu tempus mauris, id ornare orci. Integer diam est, sodales id consectetur ut, finibus ut lectus. Donec et efficitur sapien. In ullamcorper lobortis lectus, nec egestas ex dapibus ac. Curabitur mattis faucibus mauris, nec porta erat. Etiam eleifend auctor diam, a congue quam laoreet eget."
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/new_request_save_button" />-->

    </android.support.constraint.ConstraintLayout>

</android.support.v4.widget.NestedScrollView>
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Dan Hampton
  • 123
  • 2
  • 11
  • Can you put the toolbar height as attr/actionBarSize. Then the inner layout can contain the margin bottom as attr/actionBarSize. Check this sample https://github.com/wwdablu/Bakelicious/blob/master/app/src/main/res/layout/fragment_recipe_details.xml and see if that helps. – Soumya Oct 20 '17 at 19:15
  • @Soumya So under Toolbar I tried setting `android:layout_height="?attr/actionBarSize"` and under ConstraintLayout I added `android:layout_marginBottom="?attr/actionBarSize"` which resulted in no change in behavior. Still couldn't scroll to Save button. Also tried adding `android:layout_marginBottom="?attr/actionBarSize"` to NestedScrollView but it ends up with an white actionbar sized space outside the scroll view, but within the scroll view it still stops before the Save button is visible. – Dan Hampton Oct 20 '17 at 21:49
  • Do you really want the toolbar be scrollable as well ? – TheLibrarian Dec 10 '18 at 06:27

0 Answers0