2010-05-19 130 views
5

我使用下面的代碼來模擬標籤,因爲有更多的標籤,寬度可以容納用戶可以滾動左側或右側,使一個標籤按鈕可見。這一切都有效,但是我還可以通過在選項卡內容上向左或向右滑動手指,爲用戶提供在選項卡之間進行漫遊的功能。再次 - 它的作品。但是當我扔到最右邊的標籤時,它的相應按鈕幾乎看不見。我想在HorizontalScrollView裏自動滾動表格,這樣選中的選項卡按鈕就會顯示出來,但是當我執行HorizontalScrollView.smoothScrollTo(300, 0)時,什麼都不會發生。不管我第一次設置多高,參數什麼都不會移動(是的,我確實有算法來計算確切的位置)。Android:Autoscrolling Horizo​​ntalScrollView

這裏的XML代碼滾動標籤按鈕

<HorizontalScrollView android:layout_width="fill_parent" 
    android:background="@color/tabs_header" android:layout_height="55dip" 
    android:scrollbars="none" android:id="@+id/tabsButtonView"> 
    <TableLayout android:id="@+id/TableLayout01" android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <TableRow android:id="@+id/TableRow01" android:layout_width="fill_parent" android:layout_weight="1" 
      android:layout_height="0dip" android:paddingTop="5dip" android:paddingLeft="3dip"> 
      <ImageButton android:src="@drawable/linkup_logo_small" android:id="@+id/tabBtt0" 
       android:layout_width="wrap_content" android:layout_marginLeft="2dip" android:layout_marginRight="2dip" 
       android:layout_height="fill_parent" android:padding="5dip" android:background="@drawable/tab_selected"></ImageButton> 
      <ImageButton android:src="@drawable/simplyhired_small" android:id="@+id/tabBtt1" 
       android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_marginLeft="2dip" 
       android:layout_marginRight="2dip" android:padding="5dip" android:background="@drawable/tab_normal"></ImageButton> 
      <ImageButton android:src="@drawable/indeedcom_small" android:id="@+id/tabBtt2" 
       android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dip" 
       android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:background="@drawable/tab_normal"></ImageButton> 
      <ImageButton android:src="@drawable/careerbuilder_logo_small" android:id="@+id/tabBtt3" 
       android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="5dip" 
       android:layout_marginLeft="2dip" android:layout_marginRight="2dip" android:background="@drawable/tab_normal"></ImageButton> 
     </TableRow> 
    </TableLayout> 
</HorizontalScrollView> 

回答

2

沒有什麼錯Horizo​​ntalScrollView和自動卷工作完美。這只是我的代碼中失敗的初始化序列。案件結案。