ScrollView不会完全滚动

时间:2018-04-15 11:41:39

标签: android xml android-layout user-interface scrollview

我试图将布局分为两部分,其中下部应该是可滚动的。但是滚动视图不会完全滚动直到结束。

我已经尝试过使用NestedScrollView。我也已经尝试在scrollview,约束布局,滚动视图中的最后一个视图中添加边距和填充。最后的按钮是不可访问的。视图突然在该按钮上方的textview中间结束。

<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context=".mainClusterActivity"
android:id="@+id/const1"
android:layout_height="match_parent"
android:layout_width="match_parent">
<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:gravity="center"
    app:layout_constraintTop_toBottomOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
   >

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="Seen" />

    <android.support.v7.widget.AppCompatCheckBox
        android:clickable="false"
        android:id="@+id/searchedCheckBoxId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv1" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/searchedCheckBoxId"
        android:text="Learnt" />

    <android.support.v7.widget.AppCompatCheckBox
        android:id="@+id/learnedCheckBoxId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv2" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/learnedCheckBoxId"
        android:text="Mark" />

    <android.support.v7.widget.AppCompatCheckBox
        android:id="@+id/markedCheckBoxId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv3" />
</RelativeLayout>

<TextView
    android:id="@+id/wordTvId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginEnd="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="20dp"
    android:text="WORD!"
    android:textSize="80sp"
    app:layout_constraintTop_toBottomOf="@+id/relativeLayout2"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
     />
<TextView
    android:id="@+id/tempBarTv"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/black"
    app:layout_constraintTop_toBottomOf="@+id/wordTvId"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintEnd_toEndOf="parent"/>

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintTop_toBottomOf="@+id/tempBarTv"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    >

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

        <TextView
            android:id="@+id/meaningTempId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="12dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="10dp"
            android:text="Meaning"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="20dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent" />

        <ListView
            android:id="@+id/meaningLvId"
            android:layout_width="350dp"
            android:layout_height="200dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/round_rect_shape"
            android:scrollbars="vertical"
            android:textSize="30sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.488"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/meaningTempId" />

        <TextView
            android:id="@+id/temp2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:text="Synonyms"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="20sp"
            app:layout_constraintTop_toBottomOf="@+id/meaningLvId"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.069"
            app:layout_constraintStart_toStartOf="parent" />

        <ListView

            android:id="@+id/SynonymsLvId"
            android:layout_width="350dp"
            android:layout_height="250dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="48dp"
            android:background="@drawable/round_rect_shape"
            android:scrollbars="vertical"
            android:text="Meaning"
            android:textSize="30sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/temp2" />

        <TextView
           android:id="@+id/temp1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:text="Synonyms with Seached Words"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="20sp"
            app:layout_constraintTop_toBottomOf="@+id/SynonymsLvId"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.069"
            app:layout_constraintStart_toStartOf="parent" />

        <ListView

            android:id="@+id/SynonymsWithSearchedLvId"
            android:layout_width="350dp"
            android:layout_height="200dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="48dp"
            android:background="@drawable/round_rect_shape"
            android:scrollbars="vertical"
            android:text="Meaning"
            android:textSize="30sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/temp1" />

        <TextView
            android:id="@+id/notesTempTvId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="15dp"
            android:text="Notes"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/SynonymsWithSearchedLvId" />

        <TextView
            android:id="@+id/notesTvId"
            android:layout_width="350dp"
            android:layout_height="150dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="10dp"
            android:background="@drawable/round_rect_shape"
            android:text="Notes"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="23sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/notesTempTvId" />

        <Button
            android:id="@+id/addNotesId"
            android:layout_width="350dp"
            android:layout_height="50dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="15dp"
            android:background="@drawable/red_rounded_rect"
            android:text="EDIT NOTES!"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/notesTvId"
            />



    </android.support.constraint.ConstraintLayout>

   </ScrollView>

 </android.support.constraint.ConstraintLayout>

编辑:我将父约束布局更改为相对布局,现在它完全正常。仍然不知道为什么它之前没有。谢谢你的回复。

1 个答案:

答案 0 :(得分:1)

<!--I have commented where you have to change and why. do all mention changes. it will work fine-->

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/const1"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:gravity="center"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="parent">

    <TextView
        android:id="@+id/tv1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:text="Seen" />

    <android.support.v7.widget.AppCompatCheckBox
        android:id="@+id/searchedCheckBoxId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv1"
        android:clickable="false" />

    <TextView
        android:id="@+id/tv2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/searchedCheckBoxId"
        android:text="Learnt" />

    <android.support.v7.widget.AppCompatCheckBox
        android:id="@+id/learnedCheckBoxId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv2" />

    <TextView
        android:id="@+id/tv3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_toRightOf="@+id/learnedCheckBoxId"
        android:text="Mark" />

    <android.support.v7.widget.AppCompatCheckBox
        android:id="@+id/markedCheckBoxId"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_toRightOf="@+id/tv3" />
</RelativeLayout>

<TextView
    android:id="@+id/wordTvId"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center_horizontal"
    android:layout_marginStart="8dp"
    android:layout_marginTop="20dp"
    android:layout_marginEnd="8dp"
    android:text="WORD!"
    android:textSize="80sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relativeLayout2" />

<TextView
    android:id="@+id/tempBarTv"
    android:layout_width="match_parent"
    android:layout_height="1dp"
    android:background="@android:color/black"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/wordTvId" />

 <!-- Add app:layout_constraintBottom_toBottomOf="parent"
 And also set width and Height to 0dp so scrollView will take rest screen height.-->
<ScrollView
    android:layout_width="0dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/tempBarTv">

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

        <TextView
            android:id="@+id/meaningTempId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="12dp"
            android:text="Meaning"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="20dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="parent" />

        <ListView
            android:id="@+id/meaningLvId"
            android:layout_width="350dp"
            android:layout_height="200dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="8dp"
            android:background="@drawable/round_rect_shape"
            android:scrollbars="vertical"
            android:textSize="30sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.488"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/meaningTempId" />

        <!--This textView is having wrong id if you have not defined into resource. There is + sign is missing or define id into resource-->
        <TextView
            android:id="@+id/temp2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:text="Synonyms"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.069"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/meaningLvId" />

        <ListView

            android:id="@+id/SynonymsLvId"
            android:layout_width="350dp"
            android:layout_height="250dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="48dp"
            android:layout_marginEnd="8dp"
            android:background="@drawable/round_rect_shape"
            android:scrollbars="vertical"
            android:text="Meaning"
            android:textSize="30sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/temp2" />

        <TextView
            android:id="@+id/temp1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:text="Synonyms with Seached Words"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.069"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/SynonymsLvId" />

        <ListView

            android:id="@+id/SynonymsWithSearchedLvId"
            android:layout_width="350dp"
            android:layout_height="200dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="48dp"
            android:layout_marginEnd="8dp"
            android:background="@drawable/round_rect_shape"
            android:scrollbars="vertical"
            android:text="Meaning"
            android:textSize="30sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/temp1" />

        <TextView
            android:id="@+id/notesTempTvId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="8dp"
            android:layout_marginTop="15dp"
            android:layout_marginEnd="8dp"
            android:layout_marginBottom="8dp"
            android:text="Notes"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/SynonymsWithSearchedLvId" />

        <TextView
            android:id="@+id/notesTvId"
            android:layout_width="350dp"
            android:layout_height="150dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="10dp"
            android:layout_marginEnd="8dp"
            android:background="@drawable/round_rect_shape"
            android:text="Notes"
            android:textAlignment="center"
            android:textColor="@android:color/background_light"
            android:textSize="23sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/notesTempTvId" />

        <Button
            android:id="@+id/addNotesId"
            android:layout_width="350dp"
            android:layout_height="50dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="15dp"
            android:layout_marginEnd="8dp"
            android:background="@drawable/red_rounded_rect"
            android:text="EDIT NOTES!"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/notesTvId" />


    </android.support.constraint.ConstraintLayout>

</ScrollView>

</android.support.constraint.ConstraintLayout>