【发布时间】:2017-02-09 08:41:37
【问题描述】:
我的ScrollView 不会一直滚动到底部,我在这里读过一些类似的问题,例如this 和this 等等。我尝试添加 10dp padding bottom 但没有帮助。下图显示了我的问题的样子
下图是它的外观(添加了 150dp 的底部填充)
如您所见,底部还有另一个项目。我也不能简单地保持 150 padding bottom 因为列表中显示的项目数量是从数据库中获取的并且可能会有所不同,因此我需要增加/减少 填充
这是我的片段 XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.percent.PercentRelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/weekDisplayed">
<android.support.percent.PercentRelativeLayout
app:layout_heightPercent="10%"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="@+id/header"
android:background="@drawable/main_calendar_header_menu">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
app:layout_marginLeftPercent="3%"
android:layout_centerVertical="true"
android:id="@+id/prevIcon"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:background="@mipmap/arrow_left"/>
<TextView
android:text="Placeholder"
android:layout_centerHorizontal="true"
android:id="@+id/periodTextView"
android:layout_centerInParent="true"
android:textSize="17sp"
android:textStyle="bold"
android:layout_height="wrap_content"
android:layout_width="wrap_content"/>
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
app:layout_marginRightPercent="3%"
android:layout_centerVertical="true"
android:id="@+id/nextIcon"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="@mipmap/arrow_right"/>
</android.support.percent.PercentRelativeLayout>
<ScrollView
android:id="@+id/scrollView"
android:layout_below="@+id/header"
android:layout_centerHorizontal="true"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="10dp">
<RelativeLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/daysContainer"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingBottom="10dp">
</RelativeLayout>
<View
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="@drawable/shadow_middle"
android:layout_below="@+id/daysContainer"
android:id="@+id/shadowMiddle"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/shadowMiddle"
android:id="@+id/summaryContainer"
android:paddingBottom="150dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:id="@+id/commissionSummaryContainer"
android:layout_alignParentTop="true">
</RelativeLayout>
<View
android:layout_height="10dp"
android:layout_width="match_parent"
android:id="@+id/shadowBottom"
android:layout_below="@+id/commissionSummaryContainer"
android:background="@drawable/shadow_middle"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:id="@+id/absenceSummaryContainer"
android:layout_below="@+id/shadowBottom">
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</android.support.percent.PercentRelativeLayout>
@+id/daysContainer、@+id/commissionSummaryContainer 和 @+id/absenceSummaryContainer 是动态获取和创建其子视图的视图。
【问题讨论】:
-
您是否尝试在 RelativeLayout(ScrollView 的子级)中添加一个具有属性 alignParentBottom=true 的虚拟视图(如 android.support.v4.widget.Space)?
-
尝试给你的滚动视图
app:layout_heightPercent="90%" -
不要使用 PercentRelativeLayout,而是使用相对布局。
标签: android