zoukankan      html  css  js  c++  java
  • Android入门(十):界面的布局方式及其实际应用

      关于Android界面布局,网上已经有了很多非常不错的学习资料,在这里我也不班门弄斧了,推荐两篇我认为写的不错的教程,然后再重点讲一下几种布局方式的实际应用。

      教程链接:①http://www.cnblogs.com/android100/p/android-ui-detail.html

           ②http://blog.csdn.net/chenglong0513/article/details/7051177

      第一种:LinearLayout(线性布局)

      例:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal">

    <TextView
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:text="@string/promptSex"/>
    <Spinner
    android:id="@+id/spnSex"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:drawSelectorOnTop="true"
    android:prompt="@string/spnSexPrompt"/>
    android:spinnerMode="dialog"/>
    <TextView
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:text="@string/promptAge"/>
    <EditText
    android:id="@+id/edtAge"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:inputType="number"
    android:text=""/>
    <Button
    android:id="@+id/btnDoSug"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:text="@string/promptBtnDoSug"/>
    <TextView
    android:id="@+id/txtResult"
    android:layout_width="200dp"
    android:layout_height="wrap_content"
    android:textSize="20sp"
    android:text="@string/sugResult"/>
    </LinearLayout>


    因为篇幅的关系,线性布局中具体的一些属性,请读者自行查阅相关资料,毕竟属性太多了,最好的方法就是我们自己动手去实践,在实践中去掌握知识

    第二种:TableLayout(表格布局)
    例:
    <?xml version="1.0" encoding="utf-8"?>
    <TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
       android:layout_width="400dp"
       android:layout_height="match_parent"
       android:gravity="center_horizontal">
    <TableRow>
       <TextView android="name:"/>
       <TextView android="sex:"/>
       <TextView android="birthday:"/>
    </TableRow>
    <TableRow>
       <TextView android="Input name:"/>
       <TextView android="Input sex:"/>
       <TextView android="Input birthday:"/>
    </TableRow>
    <Button android:txt="enter"/>
    </TableLayout>

    读者可以把建立项目,把上面的代码复制进去,自己看一下效果,把里面的属性可以都改一下,这样有助于你加深对组件中属性作用的认识。

    RelativeLayout(相对布局)和FrameLayout(框架布局)我将会用两个实际项目的例子来进行讲解,后面两章你将看到。


  • 相关阅读:
    VC下使用Proc连接Oracle数据库
    解决ORACLE账号system被锁和修改密码
    Javascript 操作select控件大全(新增、修改、删除、选中、清空、判断存在等)[转]
    ckeditor用fckeditor的文件管理器实现图片上传
    video 播放多个视频
    web worker 发送Ajax
    对投影纹理映射的一些思考
    一个光线跟踪的简单实例
    【转载】齐次坐标概念&&透视投影变换推导
    今天开通了cnblog
  • 原文地址:https://www.cnblogs.com/peterpan-/p/5794415.html
Copyright © 2011-2022 走看看