android - 以编程方式滚动到表格布局中的一行

标签 android scroll tablelayout

我在 Scrollview 中包含一个 TableLayout。 TableLayout 在运行时以编程方式填充。该表包含航类到达信息。一个 TableLayout 已填充,我希望能够向下滚动到当前时间段。

如果我知道我想滚动到表中 100 行中的第 40 行,我该怎么做?

这是布局的 XML。提前致谢。

<LinearLayout
        android1:id="@+id/LinearLayout20"
        android1:layout_width="fill_parent"
        android1:layout_weight="1"
        android:orientation="vertical"
        android1:background="#000000" android:layout_height="10000dp" android:measureWithLargestChild="true">

    <ScrollView
            android1:id="@+id/scrollView1"
            android1:layout_width="match_parent"
            android1:layout_height="wrap_content">

        <TableLayout
                android1:id="@+id/arrivalstable"
                android1:layout_width="wrap_content"
                android1:layout_height="wrap_content">
        </TableLayout>
    </ScrollView>

</LinearLayout>

最佳答案

这可能是一个迟到的答案,但希望它可以帮助别人。如果你更密切地关注Randy's link ,你会看到你需要将 ScrollView 放在一个可运行的中,否则 child.getTop() 将始终产生 0。

final ScrollView sv = (ScrollView) findViewById(R.id.scrollView1);
TableLayout tl = (TableLayout) findViewById(R.id.arrivalstable);
int index = 40;
final View child = tl.getChildAt(index);
new Handler().post(new Runnable() {
    @Override
    public void run() {
        sv.smoothScrollTo(0, child.getBottom());
    }
});

关于android - 以编程方式滚动到表格布局中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18499953/

相关文章:

java - 从两次选择器中获取总小时数

HTML `dialog` 元素 : scroll content independently of background

android - 在 Android 中很好地设置 ListView 滚动位置

android - Android 中的花式动态列表 : TableLayout vs ListView

android - 使用 TextInputLayout 时更改 EditText 提示颜色

java - 如何在 Java/Android 中访问圣经文档

android - Gone FAB 有一段时间变得可见

jquery - 首页上 "scroll to top"效果的元素

android - 设置TableRow下TextView的layout_weight

android - 微调器扩展到屏幕边界之外