3

Оба макета доступны в библиотеке поддержки appcompat 7.Могу ли я использовать SwipeRefreshLayout внутри DrawerLayout?

Я не получаю должного результата.

У меня есть DrawerLayout как корневой макет, а затем внутри него один текстовый вид ошибки. а затем SwipeRefreshLayout

Это текстовое изображение было видно, когда корневой макет был FrameLayout. Но с тех пор, как я изменил корневую компоновку на DrawerLayout, ошибка в тексте никогда не обнаруживается!

Я использую его правильно?

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@android:color/transparent" 
    tools:context="com.timesbuzz.news.MainActivity" 
    android:id="@+id/drawer_layout"> 

    <TextView 
     android:id="@+id/errorView" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:gravity="center" 
     android:text="@string/error_view_text" 
     android:textSize="30sp" /> 

    <ProgressBar 
     android:id="@+id/loadingView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:indeterminate="true" /> 

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/contentView" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <!-- android.support.v4.view.ViewPager --> 
     <fr.castorflex.android.verticalviewpager.VerticalViewPager 
      android:id="@+id/viewPager" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" /> 

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

    <!-- The navigation drawer --> 
    <ListView 
     android:id="@+id/navdrawer" 
     android:layout_width="200dp" 
     android:layout_height="match_parent" 
     android:layout_gravity="start" 
     android:background="@android:color/white" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" 
     android:drawSelectorOnTop="false"> 
    </ListView> 
</android.support.v4.widget.DrawerLayout> 
+0

Кто голосовал вниз. заботиться, чтобы объяснить? –

+1

добавьте 'FrameLayout' в качестве первого дочернего элемента 'DrawerLayout' и' TextView, ProgressBar, SwipeRefreshLayout' в качестве дочерних элементов этого 'FrameLayout' и проверки. – Bharatesh

ответ

3

хитрости:

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/transparent" 
tools:context="com.timesbuzz.news.MainActivity" 
android:id="@+id/drawer_layout"> 

<FrameLayout 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
> 
<!-- you need to re-layout your widgets as you want --> 
<TextView 
    android:id="@+id/errorView" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:gravity="center" 
    android:text="@string/error_view_text" 
    android:textSize="30sp" /> 

<ProgressBar 
    android:id="@+id/loadingView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:indeterminate="true" /> 

<android.support.v4.widget.SwipeRefreshLayout 
    android:id="@+id/contentView" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 
    <!-- android.support.v4.view.ViewPager --> 
    <fr.castorflex.android.verticalviewpager.VerticalViewPager 
     android:id="@+id/viewPager" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

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

<!-- The navigation drawer --> 
<ListView 
    android:id="@+id/navdrawer" 
    android:layout_width="200dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:background="@android:color/white" 
    android:choiceMode="singleChoice" 
    android:divider="@android:color/transparent" 
    android:dividerHeight="0dp" 
    android:drawSelectorOnTop="false"> 
</ListView> 

+0

Благодаря полному :) –

1

Added FrameLayout как первый ребенок DrawerLayout. И добавил TextView, ProgressBar, SwipeRefreshLayout как дочерний элемент этого FrameLayout, и теперь он работает так, как ожидалось.

Я разобрался в этом вопросе, тем временем тот же трюк предложен бхаратом в комментариях.

Смежные вопросы