安卓学习第十七天:相对布局的初步使用与换源学习

来源:互联网 发布:合肥工业大学网络公选 编辑:程序博客网 时间: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系列了

 

 

0 0
原创粉丝点击