Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用滚动视图?是否有示例代码?_Android_Listview_Scrollview - Fatal编程技术网

Android 如何使用滚动视图?是否有示例代码?

Android 如何使用滚动视图?是否有示例代码?,android,listview,scrollview,Android,Listview,Scrollview,我正在做android应用程序。主要活动是listview。主要活动的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

我正在做android应用程序。主要活动是listview。主要活动的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>
单击列表视图中的每个项目时,将显示“数据”活动。列表视图中每个项目数据_活动的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_活动无法显示所有信息。问题是如何使数据_活动滚动?是否有示例代码?

将顶级视图放入滚动视图:


今天早上我试过这个方法。但是当我点击列表视图中的每个项目时,数据_活动没有出现。@ChengchengPei它到底是怎么出现的?它是否打印了日志?以下功能似乎不起作用。logcat上没有显示某些内容。代码:DataListView=ListView findViewByIdR.id.taboneviewlist;DataListView.setFastScrollEnabledtrue;mListAdapter=新的ListAdapterDatathis,data1;DataListView.SetAdapterListAdapter;DataListView.setOnItemClickListenernew OnItemClickListener{public void onItemClickAdapterView a,View v,int position,long id{//Log.vtag,something};当我将scollview放入listview时,列表视图中的项目似乎无法单击。@ChengchengPei listview不应放入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>