如何使用滚动视图?有示例代码吗?

时间:2014-09-10 22:33:18

标签: android listview scrollview

我在做Android应用程序。主要活动是列表视图。主要活动的xml文件如下。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="fill_horizontal"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >

<TabHost
    android:id="@android:id/tabhost"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" >

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

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
        </TabWidget>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

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

                <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" >

                    <TableRow
                        android:id="@+id/TableRow01"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_alignParentTop="true"
                        android:layout_centerHorizontal="true"
                        android:layout_gravity="center"
                        android:gravity="fill" 
                        android:visibility="gone">

                        <Button
                            android:id="@+id/Button01"
                            android:layout_width="48dp"
                            android:layout_height="48dp"
                            android:background="@drawable/ic_action_search"
                            android:onClick="search" />

                        <EditText
                            android:id="@+id/EditText01"
                            android:layout_width="match_parent"
                            android:layout_height="48dp"
                            android:layout_gravity="fill_horizontal"
                            android:ems="10"
                            android:hint="Employer?date?program?"
                            />
                    </TableRow>
                </TableLayout>

                <ListView
                    android:id="@+id/taboneviewlist"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="1" >
                </ListView>
            </LinearLayout>
</TabHost>

当我们点击列表视图中的每个项目时,会出现data_activity。列表视图中每个项目(data_activity)的xml文件如下所示。

<TableLayout xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TableLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
    android:id="@+id/employer"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center_vertical"
    android:gravity="center"
    android:textSize="24sp"
    android:textStyle="normal|bold" />

<View 
    android:id="@+id/employer_line"
    android:layout_height="4sp" 
    android:layout_width="fill_parent"
    android:background="#FF909090"
    android:visibility="gone"/>
<!-- Table: Date -->
<TableRow
    android:id="@+id/tableRow2"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="2dp"
    android:layout_marginRight="2dp">

    <TextView
        android:id="@+id/date_title"
        android:layout_width="100dp"
        android:layout_height="wrap_content"
        android:layout_weight="0.3"
        android:gravity="left"
        android:text="Time"
        android:textSize="20sp"
        android:textStyle="normal|bold" />

    <TextView
        android:id="@+id/date"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="0.7"
        android:gravity="right"
        android:textColor="#999999"
        android:textSize="20sp" />
</TableRow> </TableLayout>

现在data_activity无法显示所有信息。问题是如何使data_activity滚动?有没有示例代码?

1 个答案:

答案 0 :(得分:0)

将您的顶级视图放入ScrollView

<ScrollView xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <TableLayout
        android:id="@+id/TableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        ...
    </TableLayout>
</ScrollView> 
相关问题