`
hanllove001
  • 浏览: 48831 次
  • 性别: Icon_minigender_1
  • 来自: 绵阳
社区版块
存档分类
最新评论

android之layout(二)RelativeLayout, TableLayout

阅读更多

接上集讲,这集讲RelativeLayout 与TableLayout 

 

一、RelativeLayout:相对布局,这是最自由的布局,开发者可以自己配置控件的位置。

RelativeLayout 有几个重要的属性:

 

    第一类:属性值为true或false 
    android:layout_centerHrizontal  水平居中 
     android:layout_centerVertical   垂直居中 
    android:layout_centerInparent    相对于父元素完全居中 
    android:layout_alignParentBottom 贴紧父元素的下边缘 
    android:layout_alignParentLeft   贴紧父元素的左边缘 
    android:layout_alignParentRight  贴紧父元素的右边缘 
    android:layout_alignParentTop    贴紧父元素的上边缘 
    android:layout_alignWithParentIfMissing  如果对应的兄弟元素找不到的话就以父元素做参照物 

    第二类:属性值必须为id的引用名“@id/id-name” 
    android:layout_below      在某元素的下方 
    android:layout_above      在某元素的的上方 
    android:layout_toLeftOf   在某元素的左边 
    android:layout_toRightOf  在某元素的右边 

    android:layout_alignTop   本元素的上边缘和某元素的的上边缘对齐 
    android:layout_alignLeft  本元素的左边缘和某元素的的左边缘对齐 
    android:layout_alignBottom 本元素的下边缘和某元素的的下边缘对齐 
    android:layout_alignRight  本元素的右边缘和某元素的的右边缘对齐 

    第三类:属性值为具体的像素值,如30dip,40px 
    android:layout_marginBottom              离某元素底边缘的距离 
    android:layout_marginLeft                   离某元素左边缘的距离 
    android:layout_marginRight                 离某元素右边缘的距离 
    android:layout_marginTop                   离某元素上边缘的距离

 

EditText的android:hint 

设置EditText为空时输入框内的提示信息。 

android:gravity  
android:gravity属性是对该view 内容的限定.比如一个button 上面的text.  你可以设置该text 在view的靠左,靠右等位置.以button为例,android:gravity="right"则button上面的文字靠右 

android:layout_gravity 
android:layout_gravity是用来设置该view相对与起父view 的位置.比如一个button 在linearlayout里,你想把该button放在靠左、靠右等位置就可以通过该属性设置.以button为例,android:layout_gravity="right"则button靠右 

android:layout_alignParentRight 
使当前控件的右端和父控件的右端对齐。这里属性值只能为true或false,默认false。 

android:scaleType: 
android:scaleType是控制图片如何resized/moved来匹对ImageView的size。ImageView.ScaleType / android:scaleType值的意义区别: 

CENTER /center  按图片的原来size居中显示,当图片长/宽超过View的长/宽,则截取图片的居中部分显示 

CENTER_CROP / centerCrop  按比例扩大图片的size居中显示,使得图片长(宽)等于或大于View的长(宽) 

CENTER_INSIDE / centerInside  将图片的内容完整居中显示,通过按比例缩小或原来的size使得图片长/宽等于或小于View的长/宽 

FIT_CENTER / fitCenter  把图片按比例扩大/缩小到View的宽度,居中显示 

FIT_END / fitEnd   把图片按比例扩大/缩小到View的宽度,显示在View的下部分位置 

FIT_START / fitStart  把图片按比例扩大/缩小到View的宽度,显示在View的上部分位置 

FIT_XY / fitXY  把图片不按比例扩大/缩小到View的大小显示 

MATRIX / matrix 用矩阵来绘制,动态缩小放大图片来显示。 

** 要注意一点,Drawable文件夹里面的图片命名是不能大写的。

 

 

上面的内容是截取的,需要注意的地方。

下面是代码:

 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:background="#0000aa"
	android:layout_height="fill_parent">
	<TextView android:id="@+id/tv" 
		android:text="hello" android:layout_width="fill_parent"
		android:layout_height="wrap_content" 
		android:background="#aa0000" />
	<Button android:id="@+id/bt1"
		android:text="button1"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_below="@id/tv"
		android:layout_marginLeft="100dip"
	/>
	<Button android:id="@+id/bt2"
		android:text="b"
		android:gravity="right"
		android:layout_width="100dip"
		android:layout_height="wrap_content"
		android:layout_toRightOf="@id/bt1"
		android:layout_below="@id/tv"
		android:layout_marginLeft="20px"
	/>

	<TextView android:id="@+id/tv2"
		android:text="world"
		android:layout_width="wrap_content"
		android:layout_height="wrap_content"
		android:layout_alignLeft="@id/bt1"
		android:layout_below="@id/bt2"
	/>
</RelativeLayout>

可以运行看看。。。。

 

 

 

*********************************************************************************

                  传说的华丽分割线

*********************************************************************************

 

 

二、tableLayout:表格布局,将子元素的位置分配到行或列中。TableLayout布局由许多的TableRow(行) 组成,它没有列的概念,列是由行中的控件数目决定的。TableLayout布局也是实际中常用的布局方式。

TableLayout布局不会显示行、列 、单元格的边框线。

 

主要运用在某些信息的显示当中。

代码如下:

 

 

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent"
	android:background="#0000aa"
	android:layout_height="fill_parent">
	<TableRow>
		<TextView android:text="@string/row1_1" android:padding="3dip" />
		<TextView android:text="@string/row1_2" android:padding="3dip" />
		<TextView android:text="@string/row1_3" android:padding="3dip" />
	</TableRow>
	<TableRow>
		<TextView android:text="@string/row2_1" android:padding="3dip"
		android:layout_span="2" android:background="#aa0000" />
		<TextView android:text="@string/row2_2" android:padding="3dip" />
		<TextView android:text="@string/row2_3" android:padding="3dip" />
	</TableRow>
	<TableRow>
		<TextView android:text="@string/row3_1" android:padding="3dip" />
		<TextView android:text="@string/row3_2" android:padding="3dip" />
		<TextView android:text="@string/row3_3" android:padding="3dip" />
	</TableRow>
		<TableRow>
		<TextView android:text="@string/row4_1" android:padding="3dip" />
		<TextView android:text="@string/row4_2" android:padding="3dip" />
		<TextView android:text="@string/row4_3" android:padding="3dip" />
	</TableRow>
</TableLayout>


代码说明:我们建了三列,4行的表格,然后把第二行的前两列合并了,效果可以自己运行看图(我还不会传图。。。)。。。。

 


这次的附件包括了LinearLayout,RelativeLayout,TableLayout。

 

可以下载来看看。。。

分享到:
评论

相关推荐

    Android使用TableLayout动态布局实例

    `layout_column`属性定义了`View`在列中的位置,值为0表示第一列,1表示第二列。 然而,题目要求的是动态布局,这意味着我们需要在运行时根据数据生成`TableLayout`。以下是一个简单的Java代码示例,展示了如何动态...

    Android布局(RelativeLayout、TableLayout等)使用方法

    /&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="bottom" android:text="水平下对齐" /&gt; &lt;/LinearLayout&gt; &lt;/LinearLayout&gt; 2.RelativeLayout...

    Android的Layout完全介绍

    Android的Layout完全介绍 在Android开发中,Layout是构建用户界面的关键组成部分,用于组织和定位应用中的各种View组件。本文将详细介绍几种主要的Layout类型及其特点。 1. FrameLayout FrameLayout是最基础的布局...

    Android自定义Layout布局

    在Android开发中,系统提供了五种基础布局:LinearLayout、RelativeLayout、FrameLayout、TableLayout和ConstraintLayout,它们在大多数情况下能够满足基本的界面设计需求。然而,随着应用功能的复杂化和个性化界面...

    Android学习指南之Layout 布局--千锋培训

    【Android学习指南之Layout 布局】 在Android开发中,布局(Layout)是构建用户界面的核心元素,它负责组织和定位应用中的各个视图组件。本指南将着重讲解三种主要的布局类型:LinearLayout、RelativeLayout和...

    android layout

    ### Android Layout 概述 在Android开发中,`Layout`起着至关重要的作用,它用于组织和排列用户界面中的各种视图(View)组件。通过使用不同的布局方式,开发者可以创建出灵活且适应不同屏幕尺寸的应用界面。本文将...

    Android_layout.rar_android_android 布局_layout

    3. **ConstraintLayout**:作为现代Android开发中的首选布局,它通过连接约束来确定视图的位置,支持二维设计。关键属性有`app:layout_constraintLeft_toLeftOf/RightOf`、`app:layout_constraintTop_toTopOf/Bottom...

    android的layout布局种类.pdf

    Android Layout 是 Android 应用程序的用户界面布局方式,总共有五种基本布局:LinearLayout、AbsoluteLayout、RelativeLayout、FrameLayout、TableLayout。每种布局都有其特点和应用场景,本文将对每种布局进行详细...

    Android移动应用开发表格布局TableLayout的常用属性.pdf

    结合Android的其他布局,如LinearLayout、RelativeLayout、GridLayout等,开发者可以构建出丰富多样的用户界面。 需要注意的是,虽然TableLayout提供了强大的布局能力,但在处理动态数据或大量数据时,使用ListView...

    Android Layout ppt 资源共享

    本资源分享主要涵盖了Android的五大基本布局:LinearLayout、AbsoluteLayout、RelativeLayout、TableLayout以及FrameLayout,并探讨了它们之间的共享和相互嵌套。 1. **LinearLayout**:线性布局是最基础的布局方式...

    TableLayout伸缩列

    第二列和第三列的`layout_width`设为0,`layout_weight`分别为1,意味着它们将平分剩余的空间。 TableLayout的其他特性包括: 1. **可折叠行**:通过设置`android:collapseColumns`属性,可以指定某些列在空间不足...

    ex07_layout.rar_android_layout布局

    这个名为"ex07_layout.rar"的压缩包显然提供了多种布局类型的示例,包括表格布局(TableLayout)、结构布局(GridLayout)、线性布局(LinearLayout)和相对布局(RelativeLayout)。这些布局在Android应用设计中各...

    android的layout布局种类

    在这篇文章中,我们将详细介绍 Android 中的五种常见布局种类:LinearLayout、AbsoluteLayout、RelativeLayout、FrameLayout 和 TableLayout。 一、LinearLayout(线性布局) LinearLayout 是 Android 中最常用的...

    android Layout

    在Android开发中,布局(Layout)是构建用户界面的核心组件,它定义了屏幕上各个视图控件的位置和排列方式。Android提供了五种主要的布局管理器,每种都有其特定的用途和优势,使得开发者能够根据应用的需求创建出...

    TableLayout数据显示

    TableLayout中的每个View可以通过`android:layout_span`属性跨多列显示。例如,一个按钮可以设置为占据两列,而不是一列。 4. **StretchColumns**: TableLayout有一个特殊的属性`android:stretchColumns`,它...

    android 基础layout的一些布局

    二、相对布局(RelativeLayout) 相对布局允许子视图相对于其他视图的位置进行定位。每个子视图可以指定其相对于父视图或其他子视图的边界、中心或边缘的位置。例如,`android:layout_toLeftOf`表示当前视图在另一个...

    Android开发教程之Android 五大布局--千锋培训

    本教程将深入探讨Android的五大布局:FrameLayout、LinearLayout、RelativeLayout、TableLayout以及AbsoluteLayout。 **1. FrameLayout布局** FrameLayout是最基础且简单的布局方式,它将所有子视图放在同一个位置...

    TableLayout制作表格

    `TableLayout`的一个重要特点是它可以嵌套在其他布局中,例如在一个`LinearLayout`或`RelativeLayout`内。这使得开发者能够创建复杂的布局结构,同时保持表格的清晰和有序。 在实际项目中,`TableLayout`常用于显示...

Global site tag (gtag.js) - Google Analytics