2014-09-10 23 views
0

我在做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滾動?有沒有任何示例代碼?

回答

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> 
+0

今天早晨我試過這個方法。但是當我點擊列表視圖中的每個項目時,data_activity沒有出現。 – BAE 2014-09-10 22:42:35

+0

@程城沛究竟是怎麼沒有出現?它打印什麼記錄? – 2014-09-10 23:19:31

+0

看來以下功能不起作用。 「某事」不會顯示在logcat上。代碼:''DataListView =(ListView)findViewById(R.id.taboneviewlist); DataListView.setFastScrollEnabled(true); mListAdapter = new ListAdapterData(this,data1); DataListView.setAdapter(mListAdapter); DataListView.setOnItemClickListener(新OnItemClickListener(){ 公共無效onItemClick(適配器視圖一,視圖V,INT位置,長的id){// Log.v( 「標籤」, 「東西」) } }); '' – BAE 2014-09-11 20:01:48

相關問題