2012-11-24 33 views
5
<GridView 
android:id="@+id/gridView1" 
android:layout_width="wrap_content" 
android:layout_height="match_parent" 
android:columnWidth="100dip" 
android:numColumns="8" 
android:scrollbarStyle="insideOverlay" 
android:scrollbars="vertical|horizontal" 
android:stretchMode="none" > 
</GridView> 

tôi muốn sử dụng cả thanh cuộn dọc và ngang trong chế độ xem lưới như đã thấy ở trên. tôi thấy cái dọc làm việc tốt, nhưng cái nằm ngang thì không. vì vậy tôi cố gắng sửa chữa nó bằng cách đặt GridView dưới Horizontal Scroll Xem dưới dạng như dưới đâyLàm thế nào có thể sử dụng thanh cuộn ngang của GridView trong Android?

<HorizontalScrollView 
     android:id="@+id/horizontalScrollView1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <GridView 
      android:id="@+id/gridView1" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:columnWidth="100dip" 
      android:numColumns="8" 
      android:scrollbarStyle="insideOverlay" 
      android:scrollbars="vertical|horizontal" 
      android:stretchMode="none" > 
     </GridView> 

    </HorizontalScrollView> 

thậm chí tệ hơn, nó sẽ hiển thị chỉ là một cột của GridView và dĩ nhiên, không có thanh cuộn ngang.

Làm cách nào để khắc phục sự cố?

+2

Theo như tôi biết 'GridView' được cố định chiều rộng màn hình và vì vậy nó không thể di chuyển theo một hướng ngang. Đặt một 'GridView' bên trong một' HorizontalScrollView' không giải quyết vấn đề vì nó có hiệu quả cho một khoảng trống vô hạn bao quanh 'GridView' và không có thanh cuộn. – Squonk

Trả lời

0

GridView mở rộng AbsListView lớp. Trong chế độ xem lưới thực là chế độ xem danh sách có hỗ trợ cho các cột ngoài hàng. Vì vậy, nó không hỗ trợ di chuyển ngang.

Điều bạn đã làm thực chất bằng cách đặt thuộc tính android:scrollbars="vertical|horizontal" là hướng dẫn chế độ xem lưới hiển thị cả thanh cuộn dọc và ngang. Đặt thuộc tính này sẽ không cho phép cuộn trong chế độ xem (chế độ xem lưới và danh sách xem có nội dung cuộn được bật nội tại).

Nếu bạn có thể giải thích thêm một chút về những gì bạn đang cố gắng làm, một phương pháp thay thế có thể được đề xuất.

0

Giải pháp tốt nhất để sử dụng cả hai horizonal và theo chiều dọc scroolview trong android

 <HorizontalScrollView 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" 
      android:layout_below="@+id/seatLegendLayout"> 

      <FrameLayout 
       android:layout_width="fill_parent" 
       android:layout_height="match_parent"> 

       <LinearLayout 
        android:id="@+id/linearLayout_gridtableLayout" 
        android:layout_width="900dp" 
        android:layout_height="match_parent" 
        android:orientation="horizontal"> 

        <GridView 
         android:id="@+id/gridView1" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:layout_margin="4dp" 
         android:columnWidth="100dp" 
         android:gravity="center" 
         android:numColumns="9" 
         android:horizontalSpacing="1dp" 
         android:scrollbarAlwaysDrawHorizontalTrack="true" 
         android:scrollbarAlwaysDrawVerticalTrack="true" 
         android:scrollbars="horizontal" 
         android:stretchMode="none" 
         android:verticalSpacing="1dp"> 

        </GridView> 


       </LinearLayout> 
      </FrameLayout> 
     </HorizontalScrollView> 
Các vấn đề liên quan