我可以在 DrawerLayout 中使用 SwipeRefreshLayout 吗?
Can I use SwipeRefreshLayout inside DrawerLayout?
appcompat 支持库 7 中提供了这两种布局。
我没有得到正确的结果。
我将 DrawerLayout 作为根布局,然后在其中一个错误文本视图。接着是 SwipeRefreshLayout
当根布局为 FrameLayout 时,该文本视图可见。但是自从我将根布局更改为 DrawerLayout 后,textview 可能永远不会显示错误!
我使用正确吗?
<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>
添加了 FrameLayout 作为 DrawerLayout 的第一个子项。
并添加了 TextView、ProgressBar、SwipeRefreshLayout 作为该 FrameLayout 的子项,现在它按预期工作了。
我解决了这个问题,同时 bharat 在评论中提出了同样的技巧。
技巧:
<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>
appcompat 支持库 7 中提供了这两种布局。
我没有得到正确的结果。
我将 DrawerLayout 作为根布局,然后在其中一个错误文本视图。接着是 SwipeRefreshLayout
当根布局为 FrameLayout 时,该文本视图可见。但是自从我将根布局更改为 DrawerLayout 后,textview 可能永远不会显示错误!
我使用正确吗?
<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>
添加了 FrameLayout 作为 DrawerLayout 的第一个子项。 并添加了 TextView、ProgressBar、SwipeRefreshLayout 作为该 FrameLayout 的子项,现在它按预期工作了。
我解决了这个问题,同时 bharat 在评论中提出了同样的技巧。
技巧:
<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>