Android ScrollView底部在Constraint Layout中使用TextView隐藏

时间:2019-01-08 05:59:20

标签: android android-layout

文本的底部没有向上滚动。

<?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"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    tools:context=".PlaceActivity">

    <include
        android:id="@+id/place_single_appbar"
        layout="@layout/app_bar"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <ScrollView
        android:id="@+id/place_single_scrollview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:scrollbars="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/place_single_appbar">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/place_single_parent"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <ImageView
                android:id="@+id/place_single_image"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:contentDescription="@string/app_name"
                android:scaleType="centerCrop"
                android:src="@drawable/img_cristal_rock"
                app:layout_constraintTop_toTopOf="@+id/place_single_parent" />

            <android.support.constraint.ConstraintLayout
                android:id="@+id/place_single_rating_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/colorDarkest"
                android:padding="16dp"
                app:layout_constraintBottom_toTopOf="@+id/place_single_content_layout"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/place_single_image">

                <TextView
                    android:id="@+id/place_single_rating_label"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/customer_ratings"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <android.widget.RatingBar
                    android:id="@+id/place_single_ratingBar"
                    style="@style/Base.Widget.AppCompat.RatingBar.Small"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:isIndicator="true"
                    android:numStars="5"
                    android:rating="4.7"
                    android:stepSize="0.1"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toStartOf="@+id/place_single_rating_text"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/place_single_rating_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="@string/ratings_value_placeholder"
                    android:textColor="@color/colorTextDark"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

            </android.support.constraint.ConstraintLayout>

            <android.support.constraint.ConstraintLayout
                android:id="@+id/place_single_content_layout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/place_single_rating_container">

                <TextView
                    android:id="@+id/place_single_content"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/dummy_content_long"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

            </android.support.constraint.ConstraintLayout>

        </android.support.constraint.ConstraintLayout>

    </ScrollView>
</android.support.constraint.ConstraintLayout>

app_bar

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar_single"
    style="@style/AppTheme.AppBarOverlay"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:layout_weight="1"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    app:title="@string/app_name"
    app:titleTextColor="@android:color/white">
</android.support.v7.widget.Toolbar>

1 个答案:

答案 0 :(得分:0)

尝试一下

<?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"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">


    <include
        android:id="@+id/place_single_appbar"
        layout="@layout/aa"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />


    <android.support.v4.widget.NestedScrollView
        android:id="@+id/place_single_scrollview"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fillViewport="true"
        android:scrollbars="vertical"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@id/place_single_appbar">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/place_single_parent"
            android:layout_width="match_parent"
            android:layout_height="0dp">

            <ImageView
                android:id="@+id/place_single_image"
                android:layout_width="match_parent"
                android:layout_height="300dp"
                android:contentDescription="@string/app_name"
                android:scaleType="centerCrop"
                android:src="@drawable/dishu"
                app:layout_constraintTop_toTopOf="@+id/place_single_parent" />

            <android.support.constraint.ConstraintLayout
                android:id="@+id/place_single_rating_container"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@color/tv_text_color"
                android:padding="16dp"
                app:layout_constraintBottom_toTopOf="@+id/place_single_content"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/place_single_image">

                <TextView
                    android:id="@+id/place_single_rating_label"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="customer_ratings"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <android.widget.RatingBar
                    android:id="@+id/place_single_ratingBar"
                    style="@style/Base.Widget.AppCompat.RatingBar.Small"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginEnd="16dp"
                    android:layout_marginRight="16dp"
                    android:isIndicator="true"
                    android:numStars="5"
                    android:rating="4.7"
                    android:stepSize="0.1"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toStartOf="@+id/place_single_rating_text"
                    app:layout_constraintTop_toTopOf="parent" />

                <TextView
                    android:id="@+id/place_single_rating_text"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="ratings_value_placeholder"
                    android:textColor="@color/colorPrimary"
                    app:layout_constraintBottom_toBottomOf="parent"
                    app:layout_constraintEnd_toEndOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

            </android.support.constraint.ConstraintLayout>

            <TextView
                android:id="@+id/place_single_content"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp"
                android:text="@string/str_use"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@+id/place_single_rating_container"
                app:layout_constraintTop_toTopOf="@+id/place_single_rating_container" />


        </android.support.constraint.ConstraintLayout>


    </android.support.v4.widget.NestedScrollView>


</android.support.constraint.ConstraintLayout>
  

工具栏

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar_single"
    style="@style/AppTheme.AppBarOverlay"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:layout_scrollFlags="scroll|enterAlways"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    app:title="@string/app_name"
    app:titleTextColor="@android:color/white"/>