【问题标题】:LinearLayout inside SwipeRefreshLayout doesn't workSwipeRefreshLayout 中的 LinearLayout 不起作用
【发布时间】:2018-05-08 12:21:51
【问题描述】:

我有这个 XML 结构:

<ScrollView>
  <RelativeLayout>
   ..........
     <SwipeRefreshLayout>
        <LinearLayout/>
     </SwipeRefreshLayout>
          .....
  </RelativeLayout>
</ScrollView>

我正在尝试为 LinearLayout 实现 SwipeRefreshLayout,但它使我的 LinearLayout 消失了。我已经尝试将 LinearLayout 放在 ScrollView 中,但它仍然没有出现。我也不能删除主要的父母。对我来说是必要的。 有谁知道我该如何实现它?

【问题讨论】:

    标签: android scrollview android-linearlayout swiperefreshlayout


    【解决方案1】:
    • 使用NestedScrollView 代替ScrollView
    • RelativeLayout 添加为子视图,而不是 LinearLayout

    NestedScrollView 与 ScrollView 类似,但它支持在新旧版本的 Android 上同时充当嵌套滚动父项和子项。

    演示

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >
    
        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fillViewport="true">
    
              <RelativeLayout>
            .....
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    相关资源
    最近更新 更多