关于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(框架布局)我将会用两个实际项目的例子来进行讲解,后面两章你将看到。
												

Android入门(十):界面的布局方式及其实际应用的更多相关文章

  1. Android入门(十二)SQLite事务、升级数据库

    原文链接:http://www.orlion.ga/610/ 一.事务 SQLite支持事务,看一下Android如何使用事务:比如 Book表中的数据都已经很老了,现在准备全部废弃掉替换成新数据,可 ...

  2. Android入门(十)SQLite创建升级数据库

    原文链接:http://www.orlion.ga/603/ 一.创建数据库 Android为了让我们能够更加方便地管理数据库,专门提供了一个 SQLiteOpenHelper帮助类, 借助这个类就可 ...

  3. 【Android学习】四种布局方式

    一.LinearLayout 线性布局,即一行展开或者一列展开,也可以嵌套,需要注意的属性如下: android:orentation  //对齐方式 二.FrameLayout 帧布局,即一层层叠起 ...

  4. Android学习笔记④——页面的布局方式

    FrameLayout(帧布局) 这个布局的特点是简单的默认把每一个视图组件都放在边框内且放在左上角,即使添加多个视图组件,他们也都是重叠在左上角,新的视图会遮挡住旧的视图.可以根据gravity来改 ...

  5. Android开发之5大布局方式详解

    Android中常用的5大布局方式有以下几种: 线性布局(LinearLayout):按照垂直或者水平方向布局的组件. 帧布局(FrameLayout):组件从屏幕左上方布局组件. 表格布局(Tabl ...

  6. Android入门(十八)服务

    原文链接:http://www.orlion.ga/674/ 一.定义一个服务 创建一个项目ServiceDemo,然后在这个项目中新增一个名为 MyService的类,并让它继承自 Service, ...

  7. Android入门(十五)通知

    原文链接:http://www.orlion.ga/663/ 1.通知的基本用法 创建通知的步骤,首先需要一个NotificationManager来对通知进行管理,可以调用Context的getSy ...

  8. Android入门(十九)WebView

    原文链接:http://www.orlion.ga/676/ WebView可以在自己的应用程序中嵌入一个浏览器来展示网页. 创建一个项目WebViewDemo,修改activity_main.xml ...

  9. Android入门(十六)调用摄像头相册

    原文链接:http://www.orlion.ga/665/ 一.调用摄像头 创建一个项目ChoosePicDemo,修改activity_main.xml: <LinearLayout xml ...

随机推荐

  1. thinkphp一句话疑难解决笔记

    URL_PATHINFO_DEPR, depr表示 网页路径"分隔符",用"-", 有利于seo,注意是从 sername/index.php(开始的)/hom ...

  2. NoClassDefFoundError vs ClassNotFoundException

    我们先来认识一下Error 和Exception, 两个都是Throwable类的直接子类.  Javadoc 很好的说明了Error类: An Error is a subclass of Thro ...

  3. JAVA对MySQL数据库的操作

    一.导包: 使用JDBC连接MySQL数据库时,首先需要导入一个第三方的JAR包(点击下载),下载解压得到一个JAR包,并导入到JAVA项目中,如下图: 二.DBHelper类: 代码如下: impo ...

  4. NOIP2012同余方程

    描述 求关于 x的同余方程  ax ≡ 1(mod b) 的最小正整数解. 输入格式 输入文件 mod.in输入只有一行,包含两个正整数a,b,用一个空格隔开. 输出格式 输出文件 为 modmod  ...

  5. 第3月第13天 cpp模版 Iterator模式 proactor

    1.模版除了传参,还可以自动创建.而传指针只是传参而已. template <class TYPE, class FUNCTOR, class ACE_LOCK, typename TIME_P ...

  6. H5案例分享:移动端滑屏 touch事件

    移动端滑屏 touch事件 移动端触屏滑动的效果的效果在电子设备上已经被应用的越来越广泛,类似于PC端的图片轮播,但是在移动设备上,要实现这种轮播的效果,就需要用到核心的touch事件.处理touch ...

  7. C/C++ 结构体内存对齐

    内存对齐是指的是编译器在编译的时候总是会将结构体的元素的地址放在一些合适的位置使得CPU访问这些数据的效率变得更高.首先来看下面这个例子: struct A{ char a; char b; int ...

  8. C++ STL模板

    C++中的STL(Standard Template Library)用起来挺方便的,这里我们来做一下总结. 一.set set是STL中一种标准关联容器 (vector,list,string,de ...

  9. [Android Pro] 完美解决隐藏Listview和RecyclerView去掉滚动条和滑动到边界阴影的方案

    reference to : http://blog.csdn.net/ming2316780/article/details/51578621 一.首先是Listview的属性设置 设置滑动到顶部和 ...

  10. [Android Pro] ScrollView使用fillViewport设置高度为MatchParent

    reference to : http://blog.csdn.net/u012975705/article/details/49275001 之前遇到一问题,就是当使用ScrollView时,Scr ...