2013-08-02 19 views
8

Tôi quan tâm đến việc tạo màn hình bao gồm tiêu đề trong suốt và chế độ xem danh sách cuộn phía sau tiêu đề. Tôi có điều này làm việc với một lỗ hổng; thanh cuộn nhanh cũng vẽ bên dưới tiêu đề.Buộc Android Fast Scroll Bar trên ListViews để vẽ trong padding

Vì lý do nào đó, thanh công cụ dường như không tôn trọng thanh cuộn Kiểu được áp dụng cho chế độ xem danh sách. Bạn sẽ nhận thấy trong hình dưới đây rằng thanh cuộn bình thường hoạt động tốt, nhưng thanh powercroll nằm phía sau tiêu đề trong suốt.

FastScrollBar and NormalScrollBar example

Thật không may là listviews Tôi đang sử dụng sẽ thường xuyên có hàng trăm mặt hàng, do đó fastscrollbar là một điều cần thiết. Có cách nào để thiết lập "fastscrollStyle" không được ghi chép? Tôi mở cửa cho bất kỳ đề xuất! Cảm ơn bạn.

Đây là XML layout để tham khảo:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 

    <ListView 
     android:id="@+id/myListView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:clipToPadding="false" 
     android:fastScrollEnabled="true" 
     android:scrollbars="vertical" 
     android:scrollbarStyle="insideOverlay" 
     android:paddingTop="50dp"/> 

    <TextView android:text="My Header" 
       android:gravity="center" 
       android:background="#8fff0000" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp"/> 
</RelativeLayout> 

này đã được cố định trong KitKat cho ListView, tuy nhiên GridView vẫn xuất hiện để triển lãm vấn đề này. Google?

+0

Sử dụng linearlayout thay vì relativelayout. Tiêu đề ở trên cùng và đặt vị trí chế độ xem danh sách bên dưới tiêu đề. Listitems sẽ không bao giờ thấy phía sau biểu tượng tiêu đề và thanh cuộn. – Tugrul

+0

Tôi muốn các mục listview vẽ phía sau tiêu đề trong khi cũng có thanh cuộn nhanh tôn trọng phần đệm dọc của listview. Linearlayout không có cuộn nhanh và sẽ có hiệu suất rất kém nếu bạn thêm hàng nghìn mục vào đó. :-) – supereee

+0

Thx cho phản hồi này. ;) – Tugrul

Trả lời

1

Giải pháp tốt nhất là tách chế độ xem danh sách của bạn khỏi các bố cục khác, trong đó chế độ xem relativelayout chính là bố mẹ và bố cục khác là trẻ em.

EX.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
    <RelativeLayout 
       android:id"@+id/layoutHeader" 
       android:layout_width="fill_parent" 
       android:layout_height="50dp" 
       android:layout_alignParentTop="true"> 

       <TextView android:text="My Header" 
         android:gravity="center" 
         android:background="#8fff0000" 
         android:layout_width="fill_parent" 
         android:layout_height="50dp"/> 
    </RelativeLayout> 

    <RelativeLayout 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_below="+id/layoutHeader"> 
    <ListView 
     android:id="@+id/myListView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:clipToPadding="false" 
     android:fastScrollEnabled="true" 
     android:scrollbars="vertical" 
     android:scrollbarStyle="insideOverlay" 
     android:paddingTop="50dp"/> 
    </RelativeLayout> 
</RelativeLayout> 
+0

Điều này không chỉ đơn giản là vẽ listview ở phía trước của tiêu đề trong khi tạo ra một hệ thống phân cấp xem không cần thiết lớn hơn? – supereee

0

Lỗi này dường như được sửa trong 4.4. Tuy nhiên, trong các phiên bản cũ hơn, dường như không có cách giải quyết nào khác ngoài việc để padding tại 0.