android开发第二站UI布局(2)-----手机信息页面

来源:互联网 发布:大数据开发视频教程 编辑:程序博客网 时间:2024/04/30 13:35

1. 运行效果图

  

1.  设计思路(实现原理)、1)将准备好的八个图标复制到res/drawable文件夹下

    2)创建一个垂直的线性布局,并在线性布局中创建4个相对布局  

    3)在相对布局中添加相应的TextView

4)在values文件下的style.xml文件中存放抽取出来的样式

    5)创建values-zh-rCNvalues-en-rUS文件夹,并在文件夹中创建strings.xml文件(国际化)

2.应用知识点

本实验主要应用UI技术线性布局和相对布局、Android开发所面临的国际化问题、样式的抽取

3.具体实现

1)创建一个新项目命名为23 


2)在res文件夹->layout文件夹建立新布局文件linerlayoutdemo3


3)在布局中先使用线性布局将布局方向设为竖直方向

<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"    android:background="@android:color/darker_gray"    tools:context=".MainActivity"    android:orientation="vertical">
</LinearLayout>

4)在线性布局中添加四个相对布局

<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"    android:background="@android:color/darker_gray"    tools:context=".MainActivity"    android:orientation="vertical">
<RelativeLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"></RelativeLayout>
<RelativeLayout
    android:layout_width="match_parent"    android:layout_height="wrap_content"></RelativeLayout>
<RelativeLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"></RelativeLayout>
<RelativeLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"></RelativeLayout>
</LinearLayout>
5)在每一个RelativeLayout中分别添加两个TextvVew,

RelativeLayout    android:layout_width="match_parent"    android:layout_height="wrap_content">
<TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content" />
<TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content" />
</RelativeLayout>
6)向TextView中添加图片

将找到的图片文件复制到res下的drawble文件夹下


7)将图片添加到TextView下 并设置相关属性

<TextView    android:layout_width="wrap_content"    android:layout_height="wrap_content"
TextView    style="@style/tv_style"    android:layout_alignParentLeft="true"    android:layout_marginLeft="10dp"    android:drawableTop="@drawable/info"    android:text="@string/...." />
 />
8)values文件下的style.xml文件中存放抽取出来的样式

打开style.xml文件

复制所给样式

resources>

    <style name="AppBaseTheme" parent="android:Theme.Light">

 </style>

    <style name="AppTheme" parent="AppBaseTheme">

    </style>

    <!-- 宽 match——parent高  wrap_content-->

    <style name="h_wrap_content">

        <item name="android:layout_width">match_parent</item>

        <item name="android:layout_height">wrap_content</item>

    </style>

     <!-- 宽高都 match——parent -->

    <style name="tv_style">

        <item name="android:layout_width">145dp</item>

        <item name="android:layout_height">90dp</item>

        <item name="android:gravity">center</item>

        <item name="android:paddingTop">8dp</item>

        <item name="android:paddingBottom">8dp</item>

        <item name="android:drawablePadding">5dp</item>

        <item name="android:background">@android:color/white</item>

    </style>

</resources>

9)创建values-zh-rCNvalues-en-rUS文件夹,并在文件夹中创建strings.xml文件(国际化)

将app目录转换为project目录

app——>src->main->res目录下新建这两个文件夹
new->Director重命名为values-zh-rCNvalues-en-rUS
10)jstring .xml复制到这两个文件中
效果

打开两个文件
分别录入
values-zh-rCN文件夹下的strings.xml文件如下所示:

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <string name="app_name">手机信息页面</string>

    <string name="menu_settings">设置</string>

    <string name="hello_world">你好,世界!</string>

    <string name="_cloud">云通信</string>

    <string name="_bluetooth">蓝牙</string>

    <string name="_gesture">自定义手势</string>

    <string name="_gps">定位</string>

    <string name="_system_info">系统信息</string>

    <string name="_internet">网络</string>

    <string name="_language">语言设置</string>

    <string name="_set_notifycation">通知栏设置</string>

</resources>

values-en-rUS文件夹下的strings.xml文件如下所示:

<?xml version="1.0" encoding="utf-8"?>

<resources>

    <string name="app_name">phoneInfo</string>

    <string name="menu_settings">Settings</string>

    <string name="hello_world">Hello world!</string>

    <string name="_cloud">Cloud</string>

    <string name="_bluetooth">Bluetooth</string>

    <string name="_gesture">Gesture</string>

    <string name="_gps">Gps</string>

    <string name="_system_info">SystemInfo</string>

    <string name="_internet">Internet</string>

    <string name="_language">Language</string>

    <string name="_set_notifycation">Notifycation</string>

</resources>

此时ExeActivtiy中R为红色(解决方法

AppCompatActivity为系统自带,当style.xml未改变时无影响;若style.xml已改,则将

将AppCompatActivity 改为Activtity)

12)点run,选择设备完成



知识点在Android模拟器上设置(通过修改语言显示)


0 0