前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android开发(1) - 登录界面的布局演示

Android开发(1) - 登录界面的布局演示

作者头像
张云飞Vir
发布2020-03-16 15:01:07
8020
发布2020-03-16 15:01:07
举报

android开发真的是让人觉得很有乐趣的事情呢。比起windows mobile好玩多了。虽然哪个所见即所得的视图设计环境糟糕的可以。不过这样用类似描述语言(xml,html)等设计视图似乎成为了各个技术阵营的首选,WPF也是采用了这样的方式,描述性文本语言读起来还是比较舒服的。不过WPF的描述语言过于强大了,让人有种迷茫的感觉。 先看看今天的成果

效果图

如果上图所示,就是简单的登录界面了。andord的布局真的是,真的是,哪个。难以掌握的东西,哈,不过一旦了解深入点,又让人爽的不行,流式布局总是比起windows mobile的绝对布局简单而且容易控制。我是越来越倾向于流式布局的方式了,它的一点好处是适应设备时比较灵巧,wm使用了自适应dpi的方式,哪叫一个复杂啊,切不易于控制。

先说明的是,线性布局LinearLayout,可真是个重要的东西,它有个方向的属性,指示了是水平的或者是垂直的。布局里有个重要的属性叫android:background ,指定一个背景图片,例如:android:background="@drawable/images1",指定了一个资源文件的位置。说起这个资源文件,还是让我google了一番,不知道怎么放,后来常识复制粘贴到res下的drawable-hdpi目录下,居然就能用了。看的教程少,摸索者来吧,高手们才不会指出如此简单的问题,似吾等.net阵营的小菜用着恼怒的eclipse,而且还没搞清exlipse的编译按钮在那里,只知道按下run的人,怎能懂得如此难度的技巧呢。哈,自嘲一把。

回到正题,再说 布局的属性 android:layout_width="fill_parent" ,指示了填充父区域,就是父容器有多大空间,就填充多大空间。android:layout_width="wrap_content",指示了它本身需要多大空间,就像父容器索取多大的空间,怎么说呢,就是它有多胖就占多大空。而哪个fill_parent就是不胖也全占满了。 再说android:layout_weight="0.1",这个weight(重量)是个很有意思的东西。可为一个父容器的 “子控件们”设置这个重量属性,父容器根据这个重量的多少择情分给这些子控件们多大空间。同时这个属性还与子控件 宽高属性的显示(fill_parent 或者wrap_content)模式有关(影响). 在下来就布局的嵌套了。没啥说的,类似html里的div。上代码:

                    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/images1"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.9"></LinearLayout>

    <LinearLayout
        android:id="@+id/LinearLayout02"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.1"
        android:orientation="vertical">

        <LinearLayout
            android:id="@+id/LinearLayout03"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"></LinearLayout>

        <LinearLayout
            android:id="@+id/LinearLayout_account"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10px"
            android:layout_marginRight="10px"
            android:gravity="center"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/lblAccount"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.75"
                android:text="@string/accountName"
                android:textSize="12pt"></TextView>

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:text="mailto:%22 %20android:id=%22@+id/editBoxAccount"></EditText>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10px"
            android:layout_marginRight="10px"
            android:gravity="center"
            android:orientation="horizontal">

            <TextView
                android:id="@+id/lblPassword"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.75"
                android:text="@string/password"
                android:textSize="12pt"></TextView>

            <EditText
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.25"
                android:password="true"
                android:text="mailto:%22 %20android:id=%22@+id/editBoxPassword"></EditText>
        </LinearLayout>

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10px"
            android:layout_marginRight="10px"
            android:gravity="center"
            android:orientation="horizontal">

            <Button
                android:id="@+id/btnLogin"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="登录"
                android:textSize="9pt"></Button>
        </LinearLayout>
    </LinearLayout>
    </LinearLayout>

结语

早闻android大名,只到他坠入贫民级时才接受和了解,而我,还在玩微软已经放弃了的windows mobile ,.net cf开发,看样子,为毕业时听闻的一句话“跟着微软走,吃喝全都有”,却不再灵验。windows phone 7迟迟不见真面目,他面临的用户接受程度和开发商支持都是很大的挑战,而android沦为平民级了,未来还是未知之数,而重量级的xaml语言描述的wcf, silverLight,却又推广的不那么好。总之微软已经不似几年前的样子了,这个庞大的机器狂烈的运转,却未带来更多的技术变革。反而,google。。。

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 效果图
  • 结语
相关产品与服务
容器服务
腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档