自制Android RSS阅读器

作者因未能找到理想的Android RSS阅读器,决定自行开发一个简洁无广告的应用。在开发过程中遇到了RecyclerView与ConstraintLayout兼容性问题,并解决了RSS XML文档解析中常见的标签变化问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这个问题困扰我挺久了,android端找不到一款好的RSS阅读器。我就想简简单单打开自己订阅的RSS每天看一看,没有注册,没有广告,就简简单单的。终于抽了两天时间出来写了个BETA。

所有代码都放在我的Github上了。

记录一下开发过程中遇到的一些问题。

1. RecyclerView处在ConstraintLayout中出现的视图问题

视图的问题如图。

这里写图片描述

adapteronCreateViewHolder()方法中,就是按照

View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.rss_list_item, parent, false);

这样来写的。子视图的高度也都是确定的。如果这么简单就好了。问题照旧。

尝试了很久,结果症结出在ConstraintLayoutRecyclerView一起使用上。

上图中是一个fragment,有问题的fragment的根布局如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fragment_bg"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rssRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v7.widget.RecyclerView>

</android.support.constraint.ConstraintLayout>

因为其他很多地方我都排查过了,所以对这个布局心生怀疑。

我就把ConstraintLayout改成了FrameLayout,修改后的布局如下:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/fragment_bg"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/rssRecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v7.widget.RecyclerView>

</android.support.constraint.ConstraintLayout>

问题解决。

2. 对RSS的XML文档的解析

读取RSS中的内容其实就是解析一下XML文档。

RSS的格式有个大概的标准,大致就是<channel>或者<rss>开头,然后是最外层的<title>, <link>, <description>的内容;紧接着就是<item>,代表每个子条目;每个<item>标签中也有相应的<title>, <link>, <description>节点。

比较了feed.yeeyan.org/selectzhihu.com/rsshttp://www.read.org.cn/feed以及feed.androidauthority.com四个RSS,发现有三个问题:

  • <link>标签的内容,可能包含在<link>的属性中,如:<link href="http://...">
  • <description>标签有时候又叫<subtitle>
  • <item>标签有时候又叫<entry>

因此在解析的时候,将这三个问题考虑进去,大部分的RSS应该都能解析了。

简单的应用,使用sqlite作为本地存储,如果重复添加已有的RSS,就相当于刷新RSS的内容。

目前还只有简单的添加RSS,浏览其内容的功能。

陆续还会抽空把刷新,进度条和 RSS补全库等功能加上。

代码希望对大家有用。有需要改进的地方,可以邮件我或者ISSUE。

上个截图:

这里写图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值