2010-05-19 40 views
5

Tôi đang sử dụng mã sau đây để mô phỏng các tab và vì có nhiều tab mà chiều rộng có thể chứa người dùng có thể cuộn sang trái hoặc sang phải để hiển thị nút tab. Tất cả đều hoạt động, tuy nhiên tôi cũng cung cấp cho người dùng khả năng di chuyển giữa các tab bằng cách vuốt ngón tay sang trái hoặc phải trên các nội dung tab. Một lần nữa - nó hoạt động. Nhưng khi tôi chạy đến tab ngoài cùng bên phải, nút tương ứng của nó hầu như không nhìn thấy được. Tôi muốn tự động ghi bảng bên trong HorizontalScrollView để nút tab đã chọn sẽ hiển thị nhưng khi tôi thực thi HorizontalScrollView.smoothScrollTo(300, 0) không có gì xảy ra. Nó không quan trọng như thế nào cao tôi đặt đầu tiên x tham số không có gì sẽ bao giờ di chuyển (có tôi không có một thuật toán để tính toán vị trí chính xác).Android: Tự động kiểm tra HorizontalScrollView

Đây là mã XML cho di chuyển các nút tab

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

Trả lời

2

Không có gì sai với HorizontalScrollView là và autoscrolling đang làm việc một cách hoàn hảo. Nó chỉ đơn giản là một chuỗi khởi tạo đã thất bại trong mã của tôi. Trường hợp đóng cửa.

Các vấn đề liên quan