Android UI 手机信息页面

这里写图片描述这里写图片描述
经过三周的学习,老师给我们出了一个任务,做如图所示的手机信息页面,看到图案首先应该想到该怎样设置布局,什么样的布局方式最简单。可以是网格布局也可以是 线性布局的相对布局,但我第一感觉是做表格布局要简便一些。

步骤一:由于编写布局文件时,相同控件之间的外边距和宽高都是固定的。因此会产生大量重复的布局代码,为了代码简洁和重复使用可以将相同代码抽取为样式单独放在一个style.xml文件中。
这里写图片描述
步骤二:设置完样式以后,看图片看到有中文样式和英文样式,这样我们就需要考虑国际化的问题,软件在开发时是面对世界的,所以语言也肯定是多种的,比如图中所示,我们需要在res目录下建立values-zh-rCN和values-en-rUS两个文件夹,文件夹的命名有具体规定,大家可以百度搜一下这里不详细介绍。这里写图片描述
步骤三:在drawable文件夹下把所需要的图标图片都复制进去。
步骤四:我这里只展示一个英文状态下的国际化资源文件夹内容的书写这里写图片描述
这样书写比我们直接在页面编写时把text直接命名要好,因为假如直接把text命名为GPS的话,如果我们是在中文状态还需要在改正,这样国际化了,就方便一些在什么语言状态下用什么。
步骤五:页面编写,用表格布局来写

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/darker_gray">

    <GridLayout
        style="@style/lml_wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="10dp"
        android:columnCount="2">

        <TextView
            style="@style/lml_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_marginLeft="10dp"
            android:layout_rowWeight="1"
            android:drawableTop="@drawable/cloud"
            android:text="@string/_cloud"

            />

        <TextView
            style="@style/lml_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_rowWeight="1"
            android:drawableTop="@drawable/bluetooth"
            android:text="@string/_bluetooth"

            />

        <TextView
            style="@style/lml_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_columnWeight="1"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_rowWeight="1"
            android:drawableTop="@drawable/gesture"
            android:text="@string/_gesture"

            />

        <TextView
            style="@style/lml_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_rowWeight="1"
            android:drawableTop="@drawable/gps"
            android:text="@string/_gps"

            />

        <TextView
            style="@style/lml_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_rowWeight="1"
            android:drawableTop="@drawable/info"
            android:text="@string/_system_info"

            />

        <TextView
            style="@style/lml_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_rowWeight="1"
            android:drawableTop="@drawable/internet"
            android:text="@string/_internet"

            />

        <TextView
            style="@style/lml_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="0"
            android:layout_columnWeight="1"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:layout_rowWeight="1"
            android:drawableTop="@drawable/language"
            android:text="@string/_language"

            />

        <TextView
            style="@style/lml_style"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_column="1"
            android:layout_columnWeight="1"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="10dp"
            android:layout_rowWeight="1"
            android:drawableTop="@drawable/notifycation"
            android:text="@string/_set_notifycation"

            />
    </GridLayout>


</TableLayout>

在本次实验的时候遇到了很多问题,首先就是国际化的问题没有很好地理解,在页面编写的时候,例如 android:text=”@string/_language”
刚开始就直接写的 android:text=”language”,等中文的时候又得改,弄得很混乱,如果用国际化,直接在string.xml中编写好就可以
相同控件之间的外边距和宽高都是固定的,所以我们只需要将相同代码抽取为样式写在一个style文件中就可以。
还有就是Layout-column的使用,假如等于0,这个控件才是放在第一列,我在书写的时候弄错了在这个问题写成等于一,导致第一列是空白。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值