Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/182.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 约束布局中的可滚动文本视图_Android_Android Scrollview_Android Constraintlayout - Fatal编程技术网

Android 约束布局中的可滚动文本视图

Android 约束布局中的可滚动文本视图,android,android-scrollview,android-constraintlayout,Android,Android Scrollview,Android Constraintlayout,我正在处理约束布局,我有三个视图。第一个位于顶部,第二个位于视图1的相对位置,最后一个位于视图2的下方。现在在第二个视图中,我有文本视图,它应该是可滚动的。问题是scrollview的高度覆盖了整个屏幕,但我希望它具有固定的高度,并且不要将view 3移出屏幕。我不想硬编码scrollview的高度,所以我知道应该用什么其他方法来解决它。简而言之,无论文本长度如何,第二视图应保持在视图1和视图3之间 <android.support.constraint.ConstraintLayout

我正在处理约束布局,我有三个视图。第一个位于顶部,第二个位于视图1的相对位置,最后一个位于视图2的下方。现在在第二个视图中,我有文本视图,它应该是可滚动的。问题是scrollview的高度覆盖了整个屏幕,但我希望它具有固定的高度,并且不要将view 3移出屏幕。我不想硬编码scrollview的高度,所以我知道应该用什么其他方法来解决它。简而言之,无论文本长度如何,第二视图应保持在视图1和视图3之间

<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:layout_margin="20dp">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="48dp"
        android:layout_height="48dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/aandn_icon" />

    <TextView
        android:id="@+id/textView"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:minHeight="48dp"
        android:text="Lorem ipsum"
        app:layout_constraintLeft_toRightOf="@+id/imageView"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/imageView" />

    <ImageView
        android:id="@+id/imageView2"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView"
        app:srcCompat="@drawable/aandn_icon" />


    <ScrollView
        android:id="@+id/scrolltext"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        app:layout_constraintLeft_toRightOf="@+id/imageView2"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/imageView2">

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


            <TextView
                android:id="@+id/start_tv4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBaseline="@+id/sound"
                android:layout_gravity="top|left"
                android:layout_toLeftOf="@+id/sound"
                android:text="Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
Definition: A happening or sudden event that is not wanted or expected.Example: The cars collided unexpectedly on the road causing an accident.||
"
                android:textColor="#000000"
                android:textSize="20sp" />


        </android.support.constraint.ConstraintLayout>

    </ScrollView>

    <ImageView
        android:id="@+id/imageView4"
        android:layout_width="48dp"
        android:layout_height="48dp"
        android:layout_marginTop="16dp"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/scrolltext"
        app:srcCompat="@drawable/aandn_icon" />

    <TextView
        android:id="@+id/textView4"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dp"
        android:layout_marginStart="16dp"
        android:minHeight="48dp"
        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. "
        app:layout_constraintLeft_toRightOf="@+id/imageView4"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="@+id/imageView4" />

</android.support.constraint.ConstraintLayout>

您想将
TextView 4
粘贴到屏幕底部,让
滚动视图
填充在上方,但在顶部
TextView
下方。如果我的理解是正确的,以下是一种方法:

要将
textView4
粘贴到屏幕底部:

<ImageView
    android:id="@+id/imageView4"
    ...
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent" />

滚动视图的高度设置为
MATCH_CONSTRAINTS
(0dp),顶部和底部约束滚动视图的关联图像视图和底部图像视图。这将使滚动视图在这两个约束之间居中,因此需要垂直偏移来将滚动视图移动到范围的顶部。

ConstraintLayout允许您创建具有平面视图层次结构(无嵌套视图组)的大型复杂布局。


其余部分可以计算出来。

在第二个文本视图中尝试android:lines=“5”。它将在几行之后滚动。
<ScrollView
    android:id="@+id/scrolltext"
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toTopOf="@id/imageView4"
    app:layout_constraintLeft_toRightOf="@+id/imageView2"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="@+id/imageView2"
    app:layout_constraintVertical_bias="0.0">
<android.support.constraint.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"                                            
android:layout_margin="20dp">

<ImageView
 android:id="@+id/imageView"
 android:layout_width="48dp"
 android:layout_height="48dp"
 app:layout_constraintLeft_toLeftOf="parent"
 app:layout_constraintTop_toTopOf="parent"
 app:srcCompat="@drawable/ic_launcher"/>

<TextView
 android:id="@+id/textView"
 android:layout_width="0dp"
 android:layout_height="wrap_content"
 android:layout_marginLeft="16dp"
 android:layout_marginStart="16dp"
 android:minHeight="48dp"
 android:text="Lorem ipsum"
 app:layout_constraintLeft_toRightOf="@+id/imageView"
 app:layout_constraintRight_toRightOf="parent"
 app:layout_constraintTop_toTopOf="@+id/imageView"/>

<ImageView
 android:id="@+id/imageView2"
 android:layout_width="48dp"
 android:layout_height="48dp"
 android:layout_marginTop="16dp"
 app:layout_constraintLeft_toLeftOf="parent"
 app:layout_constraintTop_toBottomOf="@+id/textView"
 app:srcCompat="@drawable/ic_launcher"/>


<ScrollView
 android:id="@+id/scrolltext"
 android:layout_width="0dp"
 android:layout_height="0dp"
 app:layout_constraintBottom_toTopOf="@+id/textView4"
 app:layout_constraintHeight_default="wrap"
 app:layout_constraintLeft_toRightOf="@+id/imageView2"
 app:layout_constraintRight_toRightOf="parent"
 app:layout_constraintTop_toTopOf="@+id/imageView2"
 app:layout_constraintVertical_bias="0.0">
    <TextView
     android:id="@+id/start_tv4"
     android:layout_width="wrap_content"
     android:layout_height="0dp"
     android:layout_gravity="top|start"
     android:text="@string/huge_text"
     android:textColor="#000000"
     android:textSize="20sp"
     app:layout_constraintBottom_toTopOf="@+id/textView4"
     app:layout_constraintHeight_default="wrap"/>

</ScrollView>

<ImageView
 android:id="@+id/imageView4"
 android:layout_width="48dp"
 android:layout_height="48dp"
 android:layout_marginTop="16dp"
 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintLeft_toLeftOf="parent"
 app:layout_constraintTop_toBottomOf="@+id/scrolltext"
 app:srcCompat="@drawable/ic_launcher"/>

<TextView
 android:id="@+id/textView4"
 android:layout_width="0dp"
 android:layout_height="0dp"
 android:layout_marginLeft="16dp"
 android:layout_marginStart="16dp"
 android:minHeight="48dp"
 android:text="@string/lorem"
 app:layout_constraintBottom_toBottomOf="parent"
 app:layout_constraintHeight_default="wrap"
 app:layout_constraintLeft_toRightOf="@+id/imageView4"
 app:layout_constraintRight_toRightOf="parent"
 />