android.support.v4.widget.SwipeRefreshLayout working but it is not visible

倖福魔咒の 提交于 2019-11-27 15:53:22

your SwipeRefreshLayout should have this flag app:layout_behavior="@string/appbar_scrolling_view_behavior" instead of the inner layout, and also the coordinator layout only works with nested Layouts so you better go with NestedScrollView or RecyclerView or if you target API > 21 then setNestedScroll(true)//i'm not really sure about the name.

Hammad Nasir

As suggested by skywall, I wrapped content_main.xml in NestedScrollView and it worked!

Here's the edited 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>

Thanks, skywall!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!