0

Ich verwende eine SwipeRefreshLayout, um den Inhalt zu aktualisieren.android.support.v4.widget.SwipeRefreshLayout funktioniert, aber es ist nicht sichtbar

Das Problem ist, dass es funktioniert, aber nicht sichtbar ist, während Sie nach unten wischen.

Hier ist, wie ich SwipeRefreshLayout in XML-Datei haben:

<?xml version="1.0" encoding="utf-8"?> 
<android.support.design.widget.CoordinatorLayout 
    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" 
    android:fitsSystemWindows="true" 
    tools:context="com.abc.xyz.MainActivity"> 

    <android.support.design.widget.AppBarLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:theme="@style/AppTheme.AppBarOverlay"> 

     <android.support.v7.widget.Toolbar 
      android:id="@+id/toolbar" 
      android:layout_width="match_parent" 
      android:layout_height="?attr/actionBarSize" 
      android:background="?attr/colorPrimary" 
      app:popupTheme="@style/AppTheme.PopupOverlay"/> 

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

    <android.support.v4.widget.SwipeRefreshLayout 
     android:id="@+id/swipetorefresh" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     xmlns:android="http://schemas.android.com/apk/res/android"> 

    <include layout="@layout/content_main"/> 

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

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/fab" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="bottom|end" 
     android:layout_margin="@dimen/fab_margin" 
     android:src="@drawable/ic_add_white_24dp"/> 

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

Hier ist content_main.xml Code der Datei:

<?xml version="1.0" encoding="utf-8"?> 

<RelativeLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.abc.xyz.MainActivity" 
    tools:showIn="@layout/app_bar_main"> 

    <TextView 
     android:id="@+id/main_txt1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:textSize="17sp"/> 

    <TextView 
     android:id="@+id/main_txt2" 
     android:layout_below="@+id/main_txt1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:text="xxx" 
     android:textStyle="bold" 
     android:textSize="17sp"/> 

    <TextView 
     android:id="@+id/main_txt3" 
     android:layout_below="@+id/main_txt2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:textSize="16sp"/> 

    <TextView 
     android:id="@+id/main_txt4" 
     android:layout_below="@+id/main_txt3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:text="xxx" 
     android:textStyle="bold" 
     android:textSize="17sp"/> 

    <TextView 
     android:id="@+id/main_txt_swipetorefresh" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:layout_centerInParent="true" 
     android:gravity="center_horizontal|center_vertical"/> 

    <TextView 
     android:id="@+id/main_txt5" 
     android:layout_below="@+id/main_txt4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:textSize="16sp"/> 

    <TextView 
     android:id="@+id/main_txt6" 
     android:layout_below="@+id/main_txt5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:text="xxx" 
     android:textStyle="bold" 
     android:textSize="17sp"/> 

    <TextView 
     android:id="@+id/main_txt7" 
     android:layout_below="@+id/main_txt6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:textSize="16sp"/> 

</RelativeLayout> 

Hier ist, wie es in Java-Datei ist:

swipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.swipetorefresh); 
     swipeRefreshLayout.setColorSchemeColors(Color.parseColor("#00BCD4"), Color.parseColor("#FF9800"), Color.parseColor("#339a60")); 
     swipeRefreshLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { 
      @Override 
      public void onRefresh() { 

       swipeRefreshLayout.setRefreshing(true); 

      } 
     }); 

Bitte lassen ich weiß, was hier schief läuft?

Sorry, wenn die Frage scheint falsch formatiert. Ich bin immer noch ein Anfänger.

+0

Wie funktioniert es? In ScrollRefreshLayout ist nichts scrollbar. RecyclerView, NestedScrollView ... Und das SwipeRefreshLayout sollte 'app: layout_behavior =" @ string/appbar_scrolling_view_behavior "' darauf haben. –

+0

@EugenPechanec der Kerl spricht über 'SwipeRefreshLayout' nicht ScrollRefreshLayout –

+0

@HammadNasir Es gibt kein ScrollRefreshLayout, es ist ein Tippfehler, danke für das Aufzeigen. –

Antwort

-2

Wie von skywall vorgeschlagen, wickelte ich content_main.xml in NestedScrollView und es funktionierte!

Hier ist die bearbeitete content_main.xml:

<?xml version="1.0" encoding="utf-8"?> 

<android.support.v4.widget.NestedScrollView 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    xmlns:android="http://schemas.android.com/apk/res/android"> 

<RelativeLayout 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    app:layout_behavior="@string/appbar_scrolling_view_behavior" 
    tools:context="com.abc.xyz.MainActivity" 
    tools:showIn="@layout/app_bar_main"> 

    <TextView 
     android:id="@+id/main_txt1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:textSize="17sp"/> 

    <TextView 
     android:id="@+id/main_txt2" 
     android:layout_below="@+id/main_txt1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:text="xxx" 
     android:textStyle="bold" 
     android:textSize="17sp"/> 

    <TextView 
     android:id="@+id/main_txt3" 
     android:layout_below="@+id/main_txt2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:textSize="16sp"/> 

    <TextView 
     android:id="@+id/main_txt4" 
     android:layout_below="@+id/main_txt3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:text="xxx" 
     android:textStyle="bold" 
     android:textSize="17sp"/> 

    <TextView 
     android:id="@+id/main_txt_swipetorefresh" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:layout_centerInParent="true" 
     android:gravity="center_horizontal|center_vertical"/> 

    <TextView 
     android:id="@+id/main_txt5" 
     android:layout_below="@+id/main_txt4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:textSize="16sp"/> 

    <TextView 
     android:id="@+id/main_txt6" 
     android:layout_below="@+id/main_txt5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="5dp" 
     android:text="xxx" 
     android:textStyle="bold" 
     android:textSize="17sp"/> 

    <TextView 
     android:id="@+id/main_txt7" 
     android:layout_below="@+id/main_txt6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="xxx" 
     android:textSize="16sp"/> 

</RelativeLayout> 
    </android.support.v4.widget.NestedScrollView> 

Danke, Skywall!

0

Ihr SwipeRefreshLayout sollte diesen Flag hat app:layout_behavior="@string/appbar_scrolling_view_behavior" anstatt das innere Layout und auch der Koordinator Layout nur mit verschachtelten Layouts funktioniert, so dass Sie besser mit NestedScrollView oder RecyclerView gehen oder wenn Sie API Ziel> 21 dann setNestedScroll(true)//i'm not really sure about the name.