【问题标题】:How to next child tablelayout android如何下一个子表格布局android
【发布时间】:2016-07-25 17:57:39
【问题描述】:

我在 ScrollView 中有一个 TableLayout。 我需要点击关闭按钮进入 TableView 中的下一个 LinearLayout(动态创建),然后通过点击后退按钮返回到上一个 LinearLayout。

在创建 TableView 时遵循我的 XML:

<?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:orientation="vertical"
    android:layout_weight="1">

<LinearLayout
        android:orientation="vertical"
        android:layout_width="match_parent"
        android:id="@+id/myLayout"
        android:layout_height="match_parent"
    android:layout_weight="1">

        <android.support.v7.widget.Toolbar
            android:id="@+id/tb_pergunta"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize" />

        <ScrollView
            android:id="@+id/sv_table"
            android:layout_height="match_parent"
            android:scrollbars="horizontal|vertical"
            android:layout_width="match_parent"
            android:layout_marginTop="5dip"
            android:scrollbarStyle="outsideInset"
            android:fillViewport="true">

        <TableLayout
            android:id="@+id/tl_principal"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

        </TableLayout>
    </ScrollView>
</LinearLayout>

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="14">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal">

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Ir para pergunta nº:"
            android:id="@+id/btnProximaPergunta"
            android:visibility="gone" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/botton_back"
            android:id="@+id/btnBackGroupExpandable" />

        <EditText
            android:layout_width="99dp"
            android:layout_height="wrap_content"
            android:inputType="number"
            android:ems="10"
            android:id="@+id/edtProximaPergunta"
            android:textAlignment="center" />

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/botton_next"
            android:id="@+id/btnNextGroupExpandable" />

    </LinearLayout>
</LinearLayout>

我该怎么做?

【问题讨论】:

  • 我不明白。使用片段更好?快 你有例子吗?感谢收听。

标签: android android-linearlayout tablelayout android-tablelayout


【解决方案1】:

您可以按照here 的描述为每个 LinearLayout 随机生成一个 ID。

将这些 ID 存储在一个数组中,然后您就可以轻松地以任意顺序调用它们中的任何一个。

【讨论】:

  • 好的。但是就像我对 ScrollView 所做的那样,把它放在顶部?因为当您单击按钮时,我想将其带到活动的顶部。在 ScrollView 中找不到此操作。
  • // 获取相对于父级的顶部位置 int top = tl_principal.getTop(); // 滚动到包装 ScrollView 的顶部位置 myScrollLayout.scrollTo(0, top);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-12
  • 1970-01-01
  • 2015-03-16
  • 1970-01-01
  • 2014-02-27
相关资源
最近更新 更多