安卓学习第十七天:相对布局的初步使用与换源学习
来源:互联网 发布:合肥工业大学网络公选 编辑:程序博客网 时间:2024/06/07 14:36
#1相对布局的使用
1,对齐至控件的基准线
基准线:为了保证印刷字母整齐而划定的线
使用android:layout_toRightof来加在右边
android:layout_alignBaseline对齐基准线
代码:
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
android:layout_height="match_parent"android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"tools:context=".MainActivity"
>
<TextView
android:id="@+id/firstview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="Hello"
android:textSize="30sp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/firstview"
android:layout_alignBaseline="@+id/firstview"
android:background="#00ff00"
android:text="Fir"
/>
</RelativeLayout>
效果图:
2,与父控件的四个边缘对齐
Android:lay_alignParentRight的值只能是true或者false
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
android:layout_height="match_parent"android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"tools:context=".MainActivity"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="300px"
android:layout_below="@+id/firstview"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="43dp">
<TextView
android:id="@+id/firstview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="Hello"
android:textSize="30sp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="26dp" />
</RelativeLayout>
<![CDATA[
>]]>
</RelativeLayout>
</RelativeLayout>
效果
3,对齐父控件的中心
Android:layout_centerInParent
<RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"android:layout_width="match_parent"
android:layout_height="match_parent"android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"tools:context=".MainActivity"
>
<TextView
android:id="@+id/firstview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="Hello"
android:textSize="30sp"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
效果:
这个源缺失了很多教程文件,打算换老罗的android系列了
- 安卓学习第十七天:相对布局的初步使用与换源学习
- 安卓学习第二十一天:相对布局的使用,以及时间控件
- 学习python的第十七天
- 安卓学习第七天
- .net学习第十七天
- Java学习第十七天
- 第十七天学习笔记
- Java学习第十七天
- Python学习---第十七天
- 安卓学习笔记之相对布局relativeLayout
- 安卓学习日记——相对布局2017.3.31
- 安卓学习第二十七天:Activity与Intent
- 安卓实习第十七天
- 安卓初步学习
- 安卓学习第七天:View
- [安卓基础]学习第七天
- 设计模式学习第十七天
- python第十七天学习记录
- 图像处理函数详解——padarray
- jQuery返回顶部效果
- matlab 把m文件编译成可执行文件
- hdu 1569 方格取数(2) 网络流 最大点权独立集
- enum,EnumMap,EnumSet
- 安卓学习第十七天:相对布局的初步使用与换源学习
- Myeclipse中无法删除部署在tomcat上的工程
- OC语言注意事项一
- C语言中volatile关键字的作用
- bootstrap 精简教程
- Hibernate 乱码问题解决
- 浅谈java接口
- 计算机相关学习范围和线路
- 运算符重载