我的活动主要是ImageView,3个EditText视图和一个用于保存数据并将其发送到数据库的按钮。在我的设备上的肖像中,这通常足以适合屏幕。但是,我想要滚动功能,特别是如果设备更改为横向视图。所以我将我的约束布局嵌套到了ScrollView(以及后来的NestedScrollView建议)。就我所知,两种观点在这种情况下具有相同的行为。
我目前的布局中发生的事情是'保存'当设备处于横向时,按钮被切断。我发现如果只添加一堆填充文本中的TextView(下面的代码中的textView6),我会在纵向和横向上获得所需的滚动行为。
如何在没有填充TextView的情况下更改代码以获得正确的滚动行为?
编辑:如果我在按钮下方放置一个大的空白视图,它至少会让我滚动到横向按钮。有更好的方法吗?
<View
android:layout_width="match_parent"
android:layout_height="300dp"
app:layout_constraintTop_toBottomOf="@id/new_request_save_button"
app:layout_constraintLeft_toLeftOf="parent">
图片https://photos.app.goo.gl/vcRjaT9rGKjjH44B3
我已经尝试了我在这些页面上找到的建议但没有成功:
XML布局(textView6注释掉,因此这是有问题的代码,textView6根据需要滚动。)
<?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>