Android_RecyclerView&SwipeRefreshLayout_swiperefreshlayout不显示_解决

@作者 : 西野奈留
@博客:http://blog.csdn.net/narunishino
-2016/5/18-


沉重的教训啊!

昨天下午搞了一个下午,然后到现在才解决…..真是郁闷…

具体情况:下拉的时候swiperefreshlayout不显示。

布局文件:

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

        <android.support.v7.widget.RecyclerView
            android:id="@+id/recyclerView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
          />
</android.support.v4
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
您可以尝试使用以下代码来解决这个问题: 1. 在布局文件添加 SwipeRefreshLayoutRecyclerView: ``` <androidx.swiperefreshlayout.widget.SwipeRefreshLayout android:id="@+id/swipeRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent"> <androidx.recyclerview.widget.RecyclerView android:id="@+id/recyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /> </androidx.swiperefreshlayout.widget.SwipeRefreshLayout> ``` 2. 在代码设置 RecyclerView 的布局管理器和适配器: ``` // 设置 RecyclerView 的布局管理器 recyclerView.layoutManager = LinearLayoutManager(this) // 设置 RecyclerView 的适配器 val adapter = MyAdapter(dataList) recyclerView.adapter = adapter ``` 3. 在代码设置 SwipeRefreshLayout 的刷新监听器: ``` // 设置 SwipeRefreshLayout 的刷新监听器 swipeRefreshLayout.setOnRefreshListener { // 在这里执行刷新操作 // 刷新完成后调用 swipeRefreshLayout.isRefreshing = false swipeRefreshLayout.isRefreshing = false } ``` 至于图片高度异常的问题,您可以尝试使用 Glide 或 Picasso 等图片加载库来加载图片,并在布局文件设置图片的宽高属性,例如: ``` <ImageView android:id="@+id/imageView" android:layout_width="match_parent" android:layout_height="wrap_content" android:adjustViewBounds="true" android:scaleType="centerCrop" app:srcCompat="@drawable/image" /> ``` 其,adjustViewBounds 属性可以让 ImageView 根据图片的宽高比例自动调整高度,scaleType 属性可以设置图片的缩放类型。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值