【发布时间】:2020-08-17 15:16:51
【问题描述】:
我想要一个水平和垂直滚动的文本字段。屏幕底部是一个按钮。到目前为止它有效,但文本视图高度仅与内容相同。有没有办法生成父元素(滚动条)的高度?
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<Button
android:id="@+id/startStressTestBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
android:text="START StressTest"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
<ScrollView
android:id="@+id/main_tv_scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="100dp"
android:scrollbars="vertical"
app:layout_constraintBottom_toTopOf="@+id/startStressTestBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/text_home"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="horizontal"
android:scrollHorizontally="true"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</HorizontalScrollView>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
目标是滚动条位于按钮的底部顶部(match_parent)。所以我可以使用“整个”屏幕进行滚动。
【问题讨论】:
-
你现在拥有什么,你想拥有什么?请附上图片
-
请更好地描述您的问题?
-
目前文本视图只有内容的高度,如“wrap_content”约束。您会看到水平滚动条直接位于文本下方。我希望 textview 的高度填满屏幕上的空白区域。
标签: android layout scroll textview