問題布局
<?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>
滑動到底部效果圖
image.png
最后一條數(shù)據(jù)展示不全
解決方案兩種
第一:根布局ConstraintLayout替換為LinearLayout
第二:給ScrollVIew里邊的LineaerLayout添加底部邊距(title欄多高你就設(shè)置多高),目前title欄高度為100dp影暴,那我們就設(shè)置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>
效果圖如下
image.png