【发布时间】:2014-02-03 03:08:45
【问题描述】:
所以我有一个TableLayout,我想把它放在一个滚动视图中。但我有一个问题:
TableLayout 最初是空的,我通过点击按钮以编程方式将TableRows 添加到其中。如果我正常地将TableLayout 放入ScrollView,这工作正常。
但我想将TableLayout 放在ScrollView 的底部。所以每次我添加一个TableRow,最后一个单元格总是会对齐到父ScrollView的底部。 (有点像聊天应用程序的工作方式 - 当您按下发送时,您的消息会添加到底部,而所有其他消息都会向上推送)。
如果我使用android:layout_gravity="bottom" 来尝试实现这一点,我无法看到任何被向上推到屏幕视图之外的行(我无法向上滚动)。但是,由于某种原因,我可以向下滚动到空白处,这是不可能的,因为最后一个 TableRow 应该在底部。
基本上问题是我可以在没有TableRows 的地方向下滚动,但我不能在有TableRows 的地方向上滚动。
这是相关的 XML 代码:
<ScrollView
android:id="@+id/tableScrollView"
android:layout_width="match_parent"
android:layout_weight="0.7"
android:layout_height="0dip"
android:scrollbars="none"
android:orientation="vertical"
android:background="@drawable/stripes_background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="bottom">
<TableLayout
android:id="@+id/outputTable"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:divider="@drawable/table_divider"
android:showDividers="middle">
</TableLayout>
</RelativeLayout>
</ScrollView>
【问题讨论】:
标签: java android scrollview tablelayout