使用布局来实现手机信息页面

使用布局来实现手机信息页面

1、运行效果图


2、实现步骤

(1)、将准备好的八个图标复制到res/drawable文件夹下

 

(2)、第一种方法:创建一个垂直的线性布局,并在线性布局中创建4个相对布局,在相对布局中添加相应的TextView

<LinearLayoutxmlns: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>

    <RelativeLayoutstyle="@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>

    <RelativeLayoutstyle="@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>

    <RelativeLayoutstyle="@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>

第二种方法:使用表格布局

<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:rowCount="4"
    android:columnCount="2"
    >
    <TextView
        style="@style/tv_style"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:paddingTop="10dp"
        android:gravity="center"
        android:drawableTop="@drawable/clound"
        android:text="Cloud"
        android:layout_height="111dp"
        android:layout_width="157dp" />

    <TextView
        style="@style/tv_style"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:paddingTop="10dp"
        android:gravity="center"
        android:drawableTop="@drawable/gesture"
        android:text="Gesture"
        android:layout_height="111dp" />
    <TextView
        style="@style/tv_style"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:paddingTop="10dp"
        android:gravity="center"
        android:drawableTop="@drawable/gps"
        android:text="Gps"
        android:layout_height="114dp"
        android:layout_width="170dp" />
    <TextView
        style="@style/tv_style"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:paddingTop="10dp"
        android:gravity="center"
        android:drawableTop="@drawable/info"
        android:text="Systeminfo"
        android:layout_height="wrap_content" />

    <TextView
        style="@style/tv_style"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:paddingTop="10dp"
        android:gravity="center"
        android:drawableTop="@drawable/notifycation"
        android:text="Notifycation"
        android:layout_height="wrap_content"
        android:layout_width="170dp" />

    <TextView
        style="@style/tv_style"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"
        android:paddingTop="10dp"
        android:gravity="center"
        android:drawableTop="@drawable/language"
        android:text="Language"
        android:layout_width="143dp"
        android:layout_height="wrap_content" />

    <TextView
        style="@style/tv_style"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:layout_marginLeft="10dp"
        android:paddingTop="10dp"
        android:gravity="center"
        android:drawableTop="@drawable/internet"
        android:text="Internet"
        android:layout_height="wrap_content"
        android:layout_width="160dp" />

    <TextView
        style="@style/tv_style"
        android:layout_alignParentRight="true"
        android:layout_marginRight="10dp"
        android:paddingTop="10dp"
        android:gravity="center"
        android:drawableTop="@drawable/bluetooth"
        android:text="Bluetooth"
        android:layout_height="109dp"
        android:layout_width="154dp" />
</GridLayout>

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

<resources>

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

    </style>

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

    </style>

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

    <stylename="h_wrap_content">

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

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

    </style>

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

    <style name="tv_style">

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

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

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

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

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

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

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

    </style>

</resources>  

(5)、实现国际化,在project视图下,创建values-zh-rCN、values-en-rUS文件夹,将Value中的String.xml复制进去。


values-zh-rCN文件夹下的strings.xml文件如下所示:

<?xmlversion="1.0" encoding="utf-8"?>

<resources>

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

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

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

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

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

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

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

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

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

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

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

</resources>

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

<?xmlversion="1.0" encoding="utf-8"?>

<resources>

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

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

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

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

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

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

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

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

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

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

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

</resources>

(6)、在MainActivity中编写与用户交互的代码

public class MainActivity extends Activity {

  @Override

  protected void onCreate(BundlesavedInstanceState) {

      super.onCreate(savedInstanceState);

      setContentView(R.layout.activity_main);

  }

}

3、遇到的问题

在MianActivity中刚开始继承的是AppCompatActivity,应该为Activity。否则R文件有错误。

还有实现国际化过程将string.xml文件删掉,会导致values-zh-rCN、values-en-rUS文件夹中的string.xml文件消失。

4、使用中在设置改为chinese,页面就会改为中文显示。


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值