如何设计一个手机信息页面?

来源:互联网 发布:网络淘宝兼职可信吗 编辑:程序博客网 时间:2024/05/18 16:56

   首先呢,这次操作是在Android Studio平台下进行设计的,效果图如下:

首先将准备好的图标复制到res/drawable文件夹下,也就是上图每个应用的图标,然后便是创建一个垂直的线性布局,注意在android studio中线性布局默认为水平显示,我们需要自动修改为垂直布局,然后在垂直布局中创建四个相对布局,在相对布局中添加相应的TextView,并在values文件下的style.xml文件中存放抽取出来的样,这里只有英文截图,大家也可自行修改为中文,只要在style.xml中稍作修改即可。好,现在先给大家部分代码:

程序界面对应布局文件activity_mian.xml的代码


<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"

    android:orientation="vertical"

    tools:context=".MainActivity" >

    <RelativeLayout style="@style/h_wrap_content"

        android:layout_marginTop="10dp">

        <TextView

            style="@style/tv_style"

            android:layout_alignParentLeft="true"

            android:layout_marginLeft="10dp"

            android:drawableTop="@drawable/clound"

            android:text="@string/_cloud" />

        <TextView

            style="@style/tv_style"

            android:layout_alignParentRight="true"

            android:layout_marginRight="10dp"

            android:drawableTop="@drawable/bluetooth"

            android:text="@string/_bluetooth" />

    </RelativeLayout>

    <RelativeLayout style="@style/h_wrap_content"

        android:layout_marginTop="10dp">

        <TextView

            style="@style/tv_style"

            android:layout_alignParentLeft="true"

            android:layout_marginLeft="10dp"

            android:drawableTop="@drawable/gesture"

            android:text="@string/_gesture" />

        <TextView

            style="@style/tv_style"

            android:layout_alignParentRight="true"

            android:layout_marginRight="10dp"

            android:drawableTop="@drawable/gps"

            android:text="@string/_gps" />

    </RelativeLayout>

    <RelativeLayout style="@style/h_wrap_content"

        android:layout_marginTop="10dp">

        <TextView

            style="@style/tv_style"

            android:layout_alignParentLeft="true"

            android:layout_marginLeft="10dp"

            android:drawableTop="@drawable/info"

            android:text="@string/_system_info" />

        <TextView

            style="@style/tv_style"

            android:layout_alignParentRight="true"

            android:layout_marginRight="10dp"

            android:drawableTop="@drawable/internet"

            android:text="@string/_internet" />

    </RelativeLayout>

    <RelativeLayout style="@style/h_wrap_content"

        android:layout_marginTop="10dp">

        <TextView

            style="@style/tv_style"

            android:layout_alignParentLeft="true"

            android:layout_marginLeft="10dp"

            android:drawableTop="@drawable/language"

            android:text="@string/_language" />

        <TextView

            style="@style/tv_style"

            android:layout_alignParentRight="true"

            android:layout_marginRight="10dp"

            android:drawableTop="@drawable/notifycation"

            android:text="@string/_set_notifycation" />

    </RelativeLayout>

</LinearLayout>



这是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>


这是创建在res文件下的values-zh-rCNvalues-en-rUS文件夹下strings.xml文件的代码,因为两个代码十分相似,所以只提供英文代码,中文只需将name后的英文修改为汉字即可:

<?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>

最后用户自己需要在MainActivity中编写与用户交互的逻辑代码:

public class MainActivity extends Activity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

}

至此所有代码都提供给大家啦,当然可能需要做一些文件名上的修改。

在做这次试验项目时,我也遇到一些问题,比如创建在res文件下的两个values-zh-rCNvalues-en-rUS文件夹在Android模式下并不显示,在public才会显示。




0 0
原创粉丝点击