6. 首页模块(四)之新闻详情

上一节对欢迎模块进行了综述(可参见 2. 欢迎模块 进行了解),接下来将从首页模块开始详细介绍:

知识点:

  • 掌握新闻详情模块的开发,实现新闻详情界面的显示
  • WebView控件加载传递过来的新闻链接展示数据界面
  • 实现加载的动画效果(逐帧动画)

新闻详情:

任务综述:
首页的广告栏图片与新闻列表的条目在被点击后跳转到新闻详情界面,这个界面主要是通过WebView控件加载一个新闻链接展现界面信息的。该界面右上角有一个收藏图标,当用户处于登录状态时,点击收藏图标会把对应的新闻信息保存到数据库中,便于后续查询。当用户处于未登录状态时,点击收藏图标会提示用户“您未登录,请先登录”(新闻收藏功能在实现登录注册后会进一步完善,此处暂不处理)。

1. “新闻详情”界面

任务分析:
在头条项目中,点击广告栏图片或新闻列表条目会跳转到“新闻详情”界面,“新闻详情”界面是通过WebView控件加载传递过来的新闻链接展示界面数据的。

10186693-11f1a4b2e5ef75e1.png
“新闻详情”界面

任务实施:
(1)创建“新闻详情”界面。在activity包中创建一个NewsDetailActivity的类,并将布局文件名指定为activity_news_detail。

(2)导入界面图片。
drawable-dhpi:
collection_normal,collection_selected,app_loading_0,app_loading_1。

(3)放置界面控件。
一个WebView控件用于加载新闻地址;
一个TextView控件用于显示New Loading文字;
一个ProgressBar控件用于显示正在加载的提示。

activity_news_detail.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_news_detail"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
        <include layout="@layout/main_title_bar" />
        <WebView
            android:id="@+id/webView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" />
    </LinearLayout>
    <LinearLayout
        android:id="@+id/ll_loading"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical"
        android:visibility="gone">
        <ProgressBar
            android:layout_width="150dp"
            android:layout_height="133dp"
            android:indeterminateDrawable="@drawable/pb_loading" />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Now Loading..."
            android:textColor="@android:color/darker_gray" />
    </LinearLayout>
</RelativeLayout>

(4)实现加载的动画效果。“新闻详情”界面在数据还未加载完全时会有一个提示正在加载数据的动画效果,这种效果可以通过逐帧动画实现。创建pd_loading.xml文件,在该文件中,android:drawable表示需要显示的图片,android:duration表示显示该图片的时间。

pd_loading.xml

<?xml version="1.0" encoding="UTF-8"?>
<animation-list android:o
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值