前几天写一个项目布局时,偶然发现一个问题,ScrollView内嵌套的父容器设置layout_marginBottom时无效,已经滑动到最底部,但是文本内容距离屏幕底部并没有如预想中出现间隔,而且文本部分内容也显示不全,如下图:
调试发现只有ScrollView内嵌套的父容器设置layout_marginBottom或者layout_marginTop时会存在问题,解决方法是通过父容器内部的子view来设置layout_marginBottom或者layout_marginTop实现离上离下的间隔。
修改前布局:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:text="@string/test" />
修改后布局:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:textSize="18sp"
android:text="@string/test" />
每天一小步,十年一大步。