Android 如何在横向模式下禁用SwipeRefreshLayout
当屏幕旋转时,我想在Android 如何在横向模式下禁用SwipeRefreshLayout,android,android-recyclerview,swiperefreshlayout,Android,Android Recyclerview,Swiperefreshlayout,当屏幕旋转时,我想在横向模式下禁用SwipeRefreshLayout。必须自动禁用SwipeRefreshLayout @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDrawerToggle.onConfigurationChanged(newConfig); if (newConfig.o
横向
模式下禁用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>
@覆盖
公共无效OnConfiguration已更改(配置newConfig){
super.onConfigurationChanged(newConfig);
mDrawerToggle.onConfigurationChanged(newConfig);
if(newConfig.orientation==Configuration.orientation\u横向){
getSupportActionBar().hide();
getWindow().addFlags(WindowManager.LayoutParams.FLAG_全屏);
refresh.setEnabled(false);
refresh.setRefreshing(false);
}else if(newConfig.orientation==Configuration.orientation\u纵向){
getSupportActionBar().show();
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_全屏);
refresh.setEnabled(true);
}
}
refresh.setOnRefreshListener(新的SwipeRefreshLayout.OnRefreshListener(){
@凌驾
公共void onRefresh(){
视频数据(“视频”);
refresh.setRefreshing(true);
(新的处理程序()).postDelayed(新的可运行(){
@凌驾
公开募捐{
refresh.setRefreshing(false);
}
}, 5000);
}
});
这是我的主要观点,我不是说这是最好的方法,但它可能会起作用
在您的SwipeRefreshLayout
中,您可以询问设备是否处于scape
中,您可以这样做:
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
//Landscape mode
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig == Configuration.ORIENTATION_LANDSCAPE){
yourSwipeLayoutRefresh.setEnabled(false);
yourSwipeLayoutRefresh.setRefreshing(false);
}
}
即使
if(getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
所以我想如果方向是横向的,你可以返回false
编辑
那么试着这样做:
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
//Landscape mode
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(newConfig == Configuration.ORIENTATION_LANDSCAPE){
yourSwipeLayoutRefresh.setEnabled(false);
yourSwipeLayoutRefresh.setRefreshing(false);
}
}
注意:如果您的
SwipeLayoutRefresh
不在同一个类中,您可以将其设置为静态,然后您可以访问它,但始终询问它是否为null要禁用“SwipeFreshLayout”,您必须在横向模式下禁用它:
禁用
swipeRefreshLayout.setEnabled(false);
要启用:
swipeRefreshLayout.setEnabled(true);
现在,要查找设备的方向,可以使用以下条件:
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE){
//Do some stuff
}
当方向n发生变化时,您可能需要检测事件,因此您可以覆盖此方法:
@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)
}
我知道我必须在onConfigurationChanged方法中实现它。。但是应该调用什么来禁用它..我们可以隐藏SwipeLayoutRefresh加载吗circle@user6071487查看我的答案(底部两行代码)如果要隐藏加载循环,是否添加了
yourSwipeLayoutRefresh.setRefresh(false)代码>?不工作..仍在以横向模式刷新列表是否工作,请告诉我。如果要隐藏SwipeLayoutRefresh加载循环,请使用此。。如果(swipeRefreshLayout.isRefreshing()){swipeRefreshLayout.setRefreshing(false);}它没有隐藏圆圈您的方法代码很好,有一点是,如果您刷新并禁用了,它会一直刷新,因此无论您在何处使用swipeRefreshLayout,请将setRefreshing(false)放在其中还有,为什么要使用这一行refresh.setRefreshing(true);在刷新列表的代码中…请删除该代码并尝试,它会自动执行它不需要的操作needed@Awadesh现在在景观列表中并没有像在需要时一样刷新,但当圆圈可见时,圆圈仍然可见?我不明白,刷新后你要重新设置布局中的数据,然后它会自动运行