Android应用的所有UI组件都继承了View类,ViewGroup通常作为其他组件的容器使用。

android视图组件容器组件与布局管理器LinearLayout

ViewGroup是View的子类,ViewGroup中除了包含普通的View组件之外,还可以再次包含ViewGroup组件。


android视图组件容器组件与布局管理器LinearLayout
android常用布局:

1.linearLayout 线性布局

重要的方法和属性:

XML Attributes
Attribute Name Related Method Description
android:baselineAligned setBaselineAligned(boolean) When set to false, prevents the layout from aligning its children's baselines.
android:baselineAlignedChildIndex setBaselineAlignedChildIndex(int) When a linear layout is part of another layout that is baseline aligned, it can specify which of its children to baseline align to (that is, which child TextView).
android:gravity setGravity(int) Specifies how to place the content of an object, both on the x- and y-axis, within the object itself.
android:measureWithLargestChild When set to true, all children with a weight will be considered having the minimum size of the largest child.
android:orientation setOrientation(int) Should the layout be a column or a row? Use "horizontal" for a row, "vertical" for a column.
android:weightSum Defines the maximum weight sum.

android:gravity,设置布局管理器组件内的对其方式,支持top,right等,也可以是组合的,leftcenter_vertical等

android:orientation设置组件排列方式,水平和垂直排列



demo代码如下:

<?xml version="1.0" encoding="utf-8"?><LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_height="wrap_content"   android:orientation="vertical"   android:layout_width="fill_parent">  <TextView android:text="linearLayout测试"            android:paddingTop="20dip"             android:paddingBottom="20dip"            android:id="@+id/TextView01"             android:layout_width="fill_parent"            android:layout_height="wrap_content"             android:gravity="center"            android:soundEffectsEnabled="true" android:password="false"            android:textStyle="bold">   </TextView>      <LinearLayout       android:id="@+id/layout1"       android:gravity="center"       android:paddingBottom="20dip"       android:layout_width="fill_parent"       android:layout_height="wrap_content">           <TextView       android:id="@+id/txtName"       android:text="帐号"       android:minWidth="80dip"       android:gravity="center"       android:layout_width="wrap_content"       android:layout_height="wrap_content">        </TextView>     <EditText                android:id="@+id/edtName"              android:minWidth="120dip"             android:layout_width="fill_parent"       android:layout_height="wrap_content"     >     </EditText>   </LinearLayout>       <LinearLayout       android:id="@+id/layout2"       android:gravity="center"       android:layout_width="fill_parent"       android:layout_height="wrap_content">           <TextView       android:id="@+id/txtPsw"       android:minWidth="80dip"       android:gravity="center"       android:text="密码"       android:layout_width="wrap_content"       android:layout_height="wrap_content">        </TextView>     <EditText                android:id="@+id/edtPassword"              android:minWidth="120dip"             android:layout_width="fill_parent"       android:layout_height="wrap_content"     >     </EditText>   </LinearLayout>      <LinearLayout      android:id="@+id/layout3"      android:gravity="right"      android:layout_width="fill_parent"      android:layout_height="wrap_content"   >            <Button android:id="@+id/btnOk"        android:minWidth="70dip"        android:text="登录"        android:layout_width="wrap_content"        android:layout_height="wrap_content"      >      </Button>            <Button android:id="@+id/btnCancel"        android:minWidth="70dip"        android:text="取消"        android:layout_width="wrap_content"        android:layout_height="wrap_content"      >      </Button>   </LinearLayout></LinearLayout>

效果如下图所示:


android视图组件容器组件与布局管理器LinearLayout

注:LinearLayout 默认 android:orientation="horizontal"

转载请注明出处:http://kurting615.iteye.com/blog/1143635

更多相关文章

  1. Android软键盘弹出时把布局顶上去的解决方法
  2. android 6.0后usb otg设备不显示在文件管理器中
  3. Android学习笔记---09_深入了解各种布局技术
  4. android流式布局、待办事项应用、贝塞尔曲线、MVP+Rxjava+Retrof
  5. android用户界面-组件Widget-进度条ProgressBar
  6. Android实现计算器布局(四种布局方式)之LinearLayout线性布局
  7. flutter调用android原生组件
  8. Android常用布局有5种
  9. android中的布局简要介绍

随机推荐

  1. Android(安卓)MVP设计模式介绍(附简单Demo
  2. android Webview 上传图片兼容各android
  3. Android属性设置android:noHistory="true
  4. Handler和Message的使用之二
  5. android window类的解释及软输入法模式选
  6. Android软件安全开发实践
  7. Android(安卓)渗透测试学习手册 第四章
  8. 转载一篇详细的分析:Android(安卓)View绘
  9. Android(安卓)调用相机拍照,适配到Android
  10. Android(安卓)Service创建USB HOST通信