11

Tôi đang gặp một số khó khăn khi làm SwipeRefreshLayout tôi có thể nhìn thấy khi sử dụng chuyển hướng minh bạch, và thanh trạng thái (API Level 19). Đó là để nói, hiện tại của nó dưới thanh trạng thái (ở phía trên cùng của màn hình), khi tôi muốn nó được dưới thanh hành động.SwipeRefreshLayout được ẩn đằng sau ActionBar với thanh trạng thái trong suốt

Các ListView đang làm việc như mong đợi. Nghĩa là nội dung được hiển thị chính xác sau thanh điều hướng và không bị ẩn dưới thanh trạng thái hoặc thanh tác vụ.

Với điều này đang được nói, nếu tôi thêm thuộc tính android: fitsSystemWindows = "true" vào bố cục tương đối của tôi, SwipeRefreshLayout hoạt động bình thường. Nhưng, làm điều này làm cho listview của tôi không nhìn thấy được dưới thanh điều hướng trong suốt. Thay vào đó, các thanh điều hướng đơn giản là màu nền của tôi và không cho phép hiển thị nội dung từ danh sách xem của tôi.

Làm cách nào để có được ListView để giữ nguyên trạng thái hiện tại và cũng có thể hiển thị SwipeRefreshLayout của tôi (thay vì bị ẩn dưới thanh trạng thái, ở đầu màn hình)?

Dưới đây là cách bố trí của tôi:

<android.support.v4.widget.DrawerLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     xmlns:tools="http://schemas.android.com/tools" 
     android:id="@+id/drawer_layout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

     <RelativeLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:paddingTop="10dp" 
      android:background="#ccc" 
      android:clipToPadding="false"> 

      <android.support.v4.widget.SwipeRefreshLayout 
       android:id="@+id/swipe_container" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"> 

      <FrameLayout 
       android:id="@+id/container" 
       android:paddingLeft="@dimen/activity_horizontal_margin" 
       android:paddingRight="@dimen/activity_horizontal_margin" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:background="#ccc"> 

       <ListView 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:id="@+id/listView" 
        android:paddingTop="10dp" 
        android:fitsSystemWindows="true" 
        android:clipToPadding="false" 
        android:divider="@android:color/transparent" 
        android:layout_gravity="left|top" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceLarge" 
        android:text="No Internet Connection" 
        android:id="@+id/noInternet" 
        android:textColor="@android:color/secondary_text_light" 
        android:layout_gravity="center" /> 

       <TextView 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceMedium" 
        android:text="Pull To Refresh" 
        android:translationY="20dp" 
        android:id="@+id/nointernetSub" 
        android:textColor="@android:color/secondary_text_light" 
        android:layout_gravity="center" /> 

      </FrameLayout> 

      </android.support.v4.widget.SwipeRefreshLayout> 

     </RelativeLayout> 

    <fragment android:id="@+id/navigation_drawer" 
     android:layout_width="@dimen/navigation_drawer_width" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:name="com.package.app.NavigationDrawerFragment" 
     tools:layout="@layout/fragment_navigation_drawer" /> 

</android.support.v4.widget.DrawerLayout> 
+1

Nó đã được một thời gian dài kể từ khi câu hỏi của bạn, nhưng có lẽ bạn vẫn cần một câu trả lời. Hãy xem xét điều này: http://stackoverflow.com/questions/24413680/swiperefreshlayout-behind-actionbar – Naroh

Trả lời

3

tôi sẽ khuyên bạn sử dụng một lề

android:layout_marginTop="?android:attr/actionBarSize" 
Các vấn đề liên quan