SwipeRefreshLayout在实际设备上不起作用,仅在模拟器上起作用

时间:2018-08-03 10:16:41

标签: java android android-layout

activity_maian.xml

此代码可在仿真器上完美运行,但不能在实际设备上运行,并且由于SwipeRefreshLayout我无法向下滚动,因此在滚动时始终排在中间,请帮助我解决此问题

预先感谢!

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:id="@+id/mains">

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

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            tools:layout_editor_absoluteX="-21dp"
            tools:layout_editor_absoluteY="-2dp" />



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

    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_header"
        app:menu="@menu/drawer_view">

    </android.support.design.widget.NavigationView>

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

这是MainActivity,我给出了一个普通的刷卡刷新布局代码,该代码可在模拟器中使用,但不能在实际设备中使用。.

MainActivity.java

 @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
        swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                LoadWed();
            }
        });
        LoadWed();

 public void LoadWed(){
        webView = (WebView) findViewById(R.id.webView);
        webView.setWebViewClient(new myWebClient());
        webView.getSettings().setJavaScriptEnabled(true);
        webView.getSettings().setAppCacheEnabled(true);
        swipe.setRefreshing(true);
        webView.loadUrl("https://localhost/admin");
        webView.getSettings().setDomStorageEnabled(true);

        swipe.setColorSchemeResources(android.R.color.holo_blue_bright,
                android.R.color.holo_green_light,
                android.R.color.holo_orange_light,
                android.R.color.holo_red_light);
    }

1 个答案:

答案 0 :(得分:0)

将FrameLayout添加为DrawerLayout的第一个子项。并添加了TextView,ProgressBar,SwipeRefreshLayout作为该FrameLayout的子级,现在它可以按预期工作。

  

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:id="@+id/mains">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <android.support.v4.widget.SwipeRefreshLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/swipe">
            <WebView
                android:id="@+id/webView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                tools:layout_editor_absoluteX="-21dp"
                tools:layout_editor_absoluteY="-2dp" />
        </android.support.v4.widget.SwipeRefreshLayout>
    </FrameLayout>
    <android.support.design.widget.NavigationView
        android:id="@+id/navigation_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        app:headerLayout="@layout/navigation_header"
        app:menu="@menu/drawer_view"></android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>