【Activity的生命周期与跳转】

该博客介绍了Android应用中Activity的生命周期,以及如何实现从新闻列表页到新闻详情页的跳转。在列表页,使用RecyclerView展示新闻,详情页则通过HtmlTextView加载HTML数据。数据解析采用聚合新闻API,使用OkHttp请求并在后台线程处理,通过Handler更新UI。同时,详细讲解了点击监听和使用类名在AndroidManifest.xml中注册实现页面跳转的方法。
摘要由CSDN通过智能技术生成

功能效果展示

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-MGdzcBHV-1666318045005)

界面设计分析

上述APP界面分为两个部分,第一部分是新闻列表页,第二部分是新闻详情页,新闻列表页中可以使用recyclerView实现,详情页这里我使用了HtmlTextView接受url传回的html数据,进行显示。具体如下:

新闻详情页
此次在微信tab页添加列表,因此可以直接在fragment_news.xml文件中设置

  • 添加RecyclerView控件
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
    tools:context=".news">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
  • 创建recyclerView的布局

    对每个item来说,都包含图片,新闻标题,新闻来源,以及发布时间,因此可以做以下布局。

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/liner1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ImageView
        android:id="@+id/news_image"
        android:layout_width="140dp"
        android:layout_height="100dp"
        android:layout_weight="0"
        tools:srcCompat="@tools:sample/avatars" />
    <LinearLayout
        android:id="@+id/liner2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0"
        android:orientation="vertical">
        <TextView
            android:id="@+id/news_title"
            android:layout_width="match_parent"
            android:layout_height="80dp"
            android:text="标题"
            android:textSize="20sp" />
        <LinearLayout
            android:id="@+id/liner3"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <TextView
                android:id="@+id/news_author"
                android:layout_width="wrap_content"
                android:layout_height="20dp"
                android:textSize="16sp"
                android:layout_weight="1"
                android:text="作者" />
            <TextView
                android:id="@+id/news_date"
                android:layout_width="wrap_content"
                android:layout_height="20dp"
                android:textSize
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值