安卓学习日志 Day04 — 单词图片&界面美化

概述

继续构建Miwok应用,上次已经成功在四个页面显示了 每个词汇的 两个语言版本

接下来将在每个列表项中为 词汇添加图片 ,最后,对页面进行一下美化,即 将每个页面中列表项的背景色改为 该页面的主题色

目标

  • 图片资源添加
  • 页面外观改善(列表项的背景色等)

最终的效果,是这样(Phrases 页面不需要添加图片,因为没有合适的图片来表达短语):

在这里插入图片描述

实现步骤

更改布局

修改列表项的布局,预留一个应用显示词汇图片的区域:

最终的列表项布局分为左右两部分,左边为该词汇的图片,右边则显示词汇的 Miwok 和 English 语言版本。

而右边的显示词汇部分,又可以分为上下两部分:上面是Miwok版本、下面是English版本。

因此可以考虑使用一个水平的线性布局,再嵌套一个垂直的线性布局来实现:

在这里插入图片描述

添加图片资源

首先,将所有的图片文件 放到 资源目录下 的 drawable 文件夹当中,这里就不再截图了。

每个单词都有一个对应的图片( Phrases 页面没有),那么将图片资源的id 封装的每个 Word对象当中是一个可行的策略。

这样 就可以根据每个 Word对象的 图片资源 id 来这 列表项中的图片了。

更改 Word 类如下:为其添加一个成员变量来记录图片资源的id ,以及该成员变量的 Getter 方法:

public class Word {
   
    
    // …………
    
    /**
     * Image resource is for the word
     */
    private int imageResourceId = NO_IMAGE_PROVIDED;

    /**
     * Constant value that represents no image was provided for this word
     */
    private static final int NO_IMAGE_PROVIDED = -1;
    
    /**
     * Create a new Word object.
     *
     * @param defaultTranslation is the word in a language that the user is already familiar with
     *                           (such as English)
     * @param miwokTranslation   is the word in the Miwok language
     */
    public Word(String defaultTranslation, String miwokTranslation) {
   
        this.defaultTranslation = defaultTranslation;
        this.miwokTranslation = miwokTranslation;
    }
    
    /**
     * Create a new Word object.
     *
     * @param defaultTranslation is the word in a language that the user is already familiar with
     *                           (such as English)
     * @param miwokTranslation   is the word in the Miwok language
     * @param imageResourceId    is the drawable resource ID for the image associated with the word
     * @param audioResourceId    is the audio resource id with the word
     */
    public Word(String defaultTranslation, String miwokTranslation, int imageResourceId) {
   
        this.defaultTranslation = defaultTranslation;
        this.miwokTranslation = miwokTranslation;
        this.imageResourceId = imageResourceId;
    }
    
    /**
     * Get the image resource is for the word
     */
    public int getImageResourceId() {
   
        return imageResourceId;
    }<
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值