Today, we are learning the relative arrangement of RelativeLayout Android Studio
1. relative layout (focus): relative placement by way of the relative positioning of the controls appear in the layout so that any position;
If the relative layout of the controls placed position is not specified, the default controls will be placed in the upper left corner RelativeLayout. So first specify the location of the first control, and then go to other control layout according to a control.
2. RelativeLayout common attributes:
Relative to the parent element to the layout of the control
android: layout_centerHrizontal If the center is ture level
android: layout_centerVertical if it is ture vertically centered
android: layout_centerInparent relative to the parent element perfectly centered
android: layout_alignParentBottom located in the parent element of the lower edge of the
left edge layout_alignParentLeft positioned parent element: android
android: layout_alignParentRight located at the right edge of the parent element
android: layout_alignParentTop located on the edge of the parent element
android: layout_alignWithParentIfMissing if the corresponding sibling can not find the words to make a reference to the parent element
Attribute values must reference name "@ id / id-name" is the id of the
android: layout_below elements located below the
android: layout_above above the elements of the
android: layout_toLeftOf elements on the left side of
the right layout_toRightOf located elements: android
android: upper edge layout_alignTop the element and the upper edge of an element is aligned
android: layout_alignLeft the left edge of the left edge of an element of the element is aligned
android: a lower edge layout_alignBottom lower edge of the element and of an element is aligned
android: layout_alignRight the right of the right edge of an element and the element edge alignment
Pixel values to the properties imparted
android: from the bottom edge layout_marginBottom
android: distance from the left layout_marginLeft
android: layout_marginRight from the right edge of
android: distance from the edge on layout_marginTop
Using this knowledge learned today, do a little Demo;
Firstly, Baidu library to find skype picture; then Ali is the use of icons to find these icons; then download a color picker;
On the code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" //设置了为线性布局
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" //对局为垂直对齐
android:background="#00aff0" //设置背景色,用取色器
tools:context=".MainActivity">
<RelativeLayout //采用相对布局
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<Button
android:textColor="@android:color/white"
android:id="@+id/bt_ms_account"
android:background="@drawable/bg_blue"
android:layout_alignParentBottom="true"
android:text="MS账号"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/bt_sk_account"
android:textColor="@android:color/white"
android:layout_marginBottom="20dp"
android:layout_above="@id/bt_ms_account"
android:background="@drawable/bg_blue"
android:text="skype用户"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/im_count"
android:layout_centerHorizontal="true"
android:layout_marginBottom="0dp"
android:layout_above="@id/bt_ms_account"
android:src="@drawable/icon"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp">
<LinearLayout
android:layout_marginTop="20dp"
android:layout_marginLeft="80dp"
android:layout_marginRight="80dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_weight="1"
android:src="@drawable/windows"
android:layout_width="0dp"
android:layout_height="22dp" />
<ImageView
android:layout_weight="1"
android:src="@drawable/mail"
android:layout_width="0dp"
android:layout_height="22dp" />
<ImageView
android:layout_weight="1"
android:src="@drawable/skype"
android:layout_width="0dp"
android:layout_height="22dp" />
<ImageView
android:layout_weight="1"
android:src="@drawable/xbox"
android:layout_width="0dp"
android:layout_height="22dp" />
<ImageView
android:layout_weight="1"
android:src="@drawable/cloud"
android:layout_width="0dp"
android:layout_height="22dp" />
</LinearLayout>
<TextView
android:id="@+id/tv_count"
android:textColor="@android:color/white"
android:background="#00a3de"
android:padding="15dp"
android:layout_alignParentBottom="true"
android:textSize="20dp"
android:text="创建账号"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_login"
android:textColor="@android:color/white"
android:gravity="center"
android:layout_marginBottom="25dp"
android:layout_above="@id/tv_count"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="登录"/>
</RelativeLayout>
</LinearLayout>
已上就是今天的学习内容,加油!