【发布时间】:2014-01-30 11:18:30
【问题描述】:
所以我有一个TableLayout,我想把它放在一个滚动视图中。但我有一个问题:
TableLayout 最初是空的,我通过点击一个按钮以编程方式将TableRows 添加到它。如果我正常地将TableLayout 放入ScrollView 中(即:当我滚动时,它可以正常工作),这工作正常。
但我想让 TableLayout 位于ScrollView 的底部。所以每次我添加一个TableRow,最后一个单元格总是会对齐到父ScrollView的底部。 (有点像移动聊天的工作方式 - 当您按下发送时,您的消息被放在底部,而所有其他消息都被向上推)。
如果我使用android:layout_gravity="bottom" 尝试实现这一点,我无法向上滚动,因此我无法看到任何被向上推到屏幕视图之外的行。但是,由于某种原因,我可以向下滚动(进入空虚状态),这是不可能的,因为最后一个 TableRow 应该在底部。
这是相关的 XML 代码(LinearLayout 可能是多余的/不需要的):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@android:color/black"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_gravity="center"
android:layout_marginTop="0dp"
android:layout_weight="0.1"
android:orientation="horizontal" >
<!-- 2 Buttons here -->
</LinearLayout>
<TextView
<!-- attributes of textView> -->/>
<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" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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>
<Button
<!-- Button attributes --> />
</LinearLayout>
分频器: 背景: 3
【问题讨论】:
-
您可以使用RelativeLayout 代替LinearLayout,然后使用“alignparent_bottom”属性。希望对你有帮助
标签: java android xml scrollview tablelayout