如何在横向模式下禁用 SwipeRefreshLayout
how to disable the SwipeRefreshLayout in Landscape mode
我想在 landscape
模式下禁用 SwipeRefreshLayout
当屏幕旋转时 SwipeRefreshLayout
必须自动禁用。
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
getSupportActionBar().hide();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
refresh.setEnabled(false);
refresh.setRefreshing(false);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
getSupportActionBar().show();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
refresh.setEnabled(true);
}
}
refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
videoData("video");
refresh.setRefreshing(true);
(new Handler()).postDelayed(new Runnable() {
@Override
public void run() {
refresh.setRefreshing(false);
}
}, 5000);
}
});
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listCoordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b2100f0f">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<utils.VideoRecyclerview
android:id="@+id/videoRecyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:footerDividersEnabled="false"
android:gravity="center_vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
这是我的主要任务,我并不是说这是最好的方法,但它可能会起作用...
在你的 SwipeRefreshLayout
中,你可以询问设备是否在 Landscape
中,你可以这样做:
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
//Landscape mode
}
即使
if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
所以我想如果方向是横向,你可以 return false。
编辑
那么试试这个方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig == Configuration.ORIENTATION_LANDSCAPE){
yourSwipeLayoutRefresh.setEnabled(false);
yourSwipeLayoutRefresh.setRefreshing(false);
}
}
注意:如果你的SwipeLayoutRefresh
不在同一个class中,你可以将它设为静态然后你可以访问它但总是询问它是否不为空
要禁用 'SwiperefreshLayout',您必须在横向模式下禁用它:
禁用
swipeRefreshLayout.setEnabled(false);
启用:
swipeRefreshLayout.setEnabled(true);
现在要查找设备的方向,您可以使用此条件:
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
//Do some stuff
}
并且您可能需要在 orientationn 更改时检测事件,为此您可以覆盖此方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//Do stuff here
}
如果它已经在刷新,那么当你改变方向时它会保持刷新,所以你必须这样检查:把这段代码放在你重写的方法中。
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
}
试试这个:
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int orientation = newConfig.orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE)
refreshLayout.setEnabled(false)
}
我想在 landscape
模式下禁用 SwipeRefreshLayout
当屏幕旋转时 SwipeRefreshLayout
必须自动禁用。
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
getSupportActionBar().hide();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
refresh.setEnabled(false);
refresh.setRefreshing(false);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
getSupportActionBar().show();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
refresh.setEnabled(true);
}
}
refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
videoData("video");
refresh.setRefreshing(true);
(new Handler()).postDelayed(new Runnable() {
@Override
public void run() {
refresh.setRefreshing(false);
}
}, 5000);
}
});
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/listCoordinate"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#b2100f0f">
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<utils.VideoRecyclerview
android:id="@+id/videoRecyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:footerDividersEnabled="false"
android:gravity="center_vertical" />
</android.support.v4.widget.SwipeRefreshLayout>
</FrameLayout>
</android.support.design.widget.CoordinatorLayout>
这是我的主要任务,我并不是说这是最好的方法,但它可能会起作用...
在你的 SwipeRefreshLayout
中,你可以询问设备是否在 Landscape
中,你可以这样做:
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
//Landscape mode
}
即使
if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
所以我想如果方向是横向,你可以 return false。
编辑
那么试试这个方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig == Configuration.ORIENTATION_LANDSCAPE){
yourSwipeLayoutRefresh.setEnabled(false);
yourSwipeLayoutRefresh.setRefreshing(false);
}
}
注意:如果你的SwipeLayoutRefresh
不在同一个class中,你可以将它设为静态然后你可以访问它但总是询问它是否不为空
要禁用 'SwiperefreshLayout',您必须在横向模式下禁用它:
禁用
swipeRefreshLayout.setEnabled(false);
启用:
swipeRefreshLayout.setEnabled(true);
现在要查找设备的方向,您可以使用此条件:
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
//Do some stuff
}
并且您可能需要在 orientationn 更改时检测事件,为此您可以覆盖此方法:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
//Do stuff here
}
如果它已经在刷新,那么当你改变方向时它会保持刷新,所以你必须这样检查:把这段代码放在你重写的方法中。
if (swipeRefreshLayout.isRefreshing()) {
swipeRefreshLayout.setRefreshing(false);
}
试试这个:
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
int orientation = newConfig.orientation;
if (orientation == Configuration.ORIENTATION_LANDSCAPE)
refreshLayout.setEnabled(false)
}