在Android 里主要有五种布局方式:LinearLayout(线性布局)、FrameLayout(单帧布局)、RelativeLayout(相对布局)、AbsoluteLayout(绝对布局)、 TableLayout(表格布局)。 我所了解的布局方式只有LinearLayout(线性布局)和RelativeLayout(相对布局)两种。
LinearLayout(线性布局)是按照水平方向(horizontal)和垂直方向(vertical)依次排列元素,每一个元素都位于前一个元素之后。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/container"    android:layout_width="match_parent"    android:layout_height="match_parent"    tools:context="com.example.surface.MainActivity"    tools:ignore="MergeRootFrame"    android:orientation="vertical" >        <LinearLayout        android:layout_width="match_parent"        android:layout_height="wrap_content"        android:orientation="horizontal" >                <Button             android:id="@+id/button1"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0.20"            android:onClick="found"            android:text="@string/text_add" />        <Button            android:id="@+id/button2"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0.39"            android:onClick="found"            android:text="@string/pause" />        <Button            android:id="@+id/button3"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0.31"            android:onClick="found"            android:text="@string/resume" />        <Button            android:id="@+id/button4"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_weight="0.33"            android:onClick="found"            android:text="@string/stop" />    </LinearLayout>        <TextView android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="sssssssssss" />    </LinearLayout>

整体上是垂直方向(vertical)布局,在设置按钮(Button)时插入水平方向(horizontal)布局。如下图:




元素属性android:layout_weight用于描述该元素在空间中所占的大小比例,如:这四个按钮(Button)在水平方向所占的大小比例。这个元素刚开始的时候不明白什么意思,最近才明白。

更多相关文章

  1. Android很有用的代码片段
  2. android 五种 布局文件
  3. android 相对布局属性说明
  4. Android了解
  5. android 传感器使用与开发----方向传感器
  6. Android禁止横屏竖屏切换
  7. android studio 线性布局LinearLayout
  8. Android禁止横屏竖屏切换
  9. Android(安卓)解析XML文件方法

随机推荐

  1. 查看Android系统内存使用的方法
  2. android activity 切换流程
  3. Android(安卓)应用程序退出的四种方法
  4. 【android】使用部分模拟器出现兼容问题E
  5. Pro Android学习笔记(五):了解Content Provi
  6. WindowManager实现悬浮窗口
  7. 第四章 Android开发三大基石—Activity、
  8. Android中的观察者模式简单使用
  9. Android(安卓)Selector用法小记
  10. Android——使用ContentProvider在应用间