问题布局
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="title"
android:gravity="center"
android:textSize="22sp"
android:textStyle="bold"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="first" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="2" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="3" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="4" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="5" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="6" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="7" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="8" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="9" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="10" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="11" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="12" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="13" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="14" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="15"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="last"
/>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
滑动到底部效果图
最后一条数据展示不全
解决方案两种
第一:根布局ConstraintLayout替换为LinearLayout
第二:给ScrollVIew里边的LineaerLayout添加底部边距(title栏多高你就设置多高),目前title栏高度为100dp,那我们就设置LineaerLayout底部边距paddingBottom="100dp"
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="100dp"
android:background="@color/colorPrimary"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:text="title"
android:gravity="center"
android:textSize="22sp"
android:textStyle="bold"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="100dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="first" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="2" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="3" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="4" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="5" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="6" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="7" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="8" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="9" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="10" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="11" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="12" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="13" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="14" />
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="15"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="55dp"
android:gravity="center"
android:text="last"
/>
</LinearLayout>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
效果图如下