1. 程式人生 > >Android基礎之LinerarLayout

Android基礎之LinerarLayout

每天一個小目標,你會變得很強大。

先上只用LinerarLayout佈局完成一個登陸介面,效果圖以及藍圖奉上:

所有的佈局以及控制元件都是景觀的子類。

先來點取景功能類常用的屬性:

屬性

含義

機器人:背景

設定背景

機器人:點選

設定檢視是否響應單擊事件

機器人:可見

控制檢視的可見性

機器人:可聚焦

控制元件檢視是否可以焦點電子雜誌

機器人:ID

檢視設定識別符號,可通過findViewById 方法獲取

再來點的ViewGroup中的常用屬性(ViewGroup中為檢視的子類):

屬性

含義

機器人:layout_height

指定該子元件的佈局高度

機器人:layout_width

指定該子元件的佈局寬度

詳細程式碼如下:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns: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:padding="10dp"
    android:orientation="vertical"
    tools:context=".MainActivity">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:id="@+id/textView"
            android:background="#fff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登入"/>
    </LinearLayout>
    <LinearLayout
        android:background="#fff"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        >
        <EditText
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="手機號"/>
        <EditText
            android:id="@+id/password"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="密碼"/>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <Button
                android:id="@+id/signin"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:background="#fff"
                android:text="註冊"
                />

            <Button
                android:layout_marginLeft="200dp"
                android:id="@+id/login"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="登入"
                />
        </LinearLayout>
    </LinearLayout>
</LinearLayout>

程式碼中的按鈕,TextView的的,的EditText上為常用的控制元件,這裡只需照敲即可,我會在後續的教程中逐步為大家講解。

到這裡就完成啦,繼續努力學習中,如有問題歡迎提問。奮鬥小青年GO!....