class 4

1.與主程序混合在一起

2.寫在XML中(建議使用這種方式)

用于顯示數(shù)據(jù)议泵,圖片或者其他信息的組建叫做VIEW鬓催。

涉及到布局(Layout)和常用控件(View)

1、線性布局和相對布局

2恨锚、比較常用的控件View(寬高、顏色猴伶、邊距、是否可見蜗顽、內(nèi)容居中布卡、在父控件中的位置雇盖、點擊事件)

3、TextView(顯示文本)崔挖、EditText(編輯框?qū)傩詉nputType常用事件及特有事件addTextChangedListener)、Button(點擊按鈕)ImageView(src庵寞、background、scaleType)

2圖形界面的五大布局

五大布局Layout:

LinearLayout線性布局

RelativeLayout相對布局

AbsoluteLayout絕對布局

GridView表格布局

FrameLayout幀布局

線性布局的倆個方向:

垂直(vertical)

水平(horizontal)

決定垂直還是水平的屬性為Orientation

·RelativeLayout相對布局

android:layout_toRightOf在指定控件的右邊

android:layout_toLeftOf在指定控件的左邊

android:layout_above在指定控件的上邊

android:layout_below在指定控件的下邊

android:layout_alignBaseline跟指定控件水平對齊

android:layout_alignLeft跟指定控件左對齊

android:layout_alignRight跟指定控件右對齊

android:layout_alignTop跟指定控件頂部對齊

android:layout_alignBottom跟指定控件底部對齊

android:layout_alignParentLeft是否跟父布局左對齊

android:layout_alignParentTop是否跟父布局頂部對齊

android:layout_alignParentRight是否跟父布局右對齊

android:layout_alignParentBottom是否跟父布局底部對齊

android:layout_centerVertical在父布局中垂直居中

android:layout_centerHorizontal在父布局中水平居中

android:layout_centerInParent在父布局中居中

編寫這個程序的代碼:

"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:paddingBottom="@dimen/activity_vertical_margin"

android:paddingLeft="@dimen/activity_horizontal_margin"

android:paddingRight="@dimen/activity_horizontal_margin"

android:paddingTop="@dimen/activity_vertical_margin"

tools:context=".MainActivity"

android:orientation="vertical"

android:background="#FFFFFF"

android:gravity="top|left"

>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

android:layout_width="65dp"

android:layout_height="wrap_content"

android:text="用戶名"

android:textSize="16sp"

/>

android:layout_width="200dp"

android:layout_height="wrap_content"

android:hint="請輸入 登錄 用戶名"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

android:layout_width="65dp"

android:layout_height="wrap_content"

android:text="密碼"

android:textSize="16sp"

/>

android:layout_width="200dp"

android:layout_height="wrap_content"

android:hint="請輸入 密碼"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

android:layout_width="65dp"

android:layout_height="wrap_content"

android:text="年齡"

android:textSize="16sp"

/>

android:layout_width="200dp"

android:layout_height="wrap_content"

android:hint="請輸入 年齡"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

android:layout_width="65dp"

android:layout_height="wrap_content"

android:text="生日"

android:textSize="16sp"

/>

android:layout_width="200dp"

android:layout_height="wrap_content"

android:hint="請輸入 您的生日"

/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:orientation="horizontal"

>

android:layout_width="65dp"

android:layout_height="wrap_content"

android:text="電話"

android:textSize="16sp"

/>

android:layout_width="200dp"

android:layout_height="wrap_content"

android:hint="請輸入 您的電話"

/>

android:layout_width="265dp"

android:layout_height="wrap_content"

android:hint="注冊"

android:layout_gravity="center_vertical"

/>

編寫這個程序的代碼:

"1.0"encoding="utf-8"?>

"http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/img1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"

android:layout_centerInParent="true"

/>

android:id="@+id/img2"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"

android:layout_above="@id/img1"

android:layout_centerInParent="true"

/>

android:id="@+id/img3"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"

android:layout_alignTop="@id/img1"

android:layout_toLeftOf="@id/img1"

/>

android:id="@+id/img4"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"

android:layout_alignTop="@id/img1"

android:layout_toRightOf="@id/img1"

/>

android:id="@+id/img5"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:src="@drawable/ic_launcher"

android:layout_below="@id/img1"

android:layout_centerInParent="true"

/>


最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市古沥,隨后出現(xiàn)的幾起案子瘸右,更是在濱河造成了極大的恐慌,老刑警劉巖岩齿,帶你破解...
    沈念sama閱讀 217,509評論 6 504
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件太颤,死亡現(xiàn)場離奇詭異,居然都是意外死亡盹沈,警方通過查閱死者的電腦和手機龄章,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,806評論 3 394
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人做裙,你說我怎么就攤上這事岗憋。” “怎么了锚贱?”我有些...
    開封第一講書人閱讀 163,875評論 0 354
  • 文/不壞的土叔 我叫張陵澜驮,是天一觀的道長。 經(jīng)常有香客問我惋鸥,道長杂穷,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,441評論 1 293
  • 正文 為了忘掉前任卦绣,我火速辦了婚禮耐量,結果婚禮上,老公的妹妹穿的比我還像新娘滤港。我一直安慰自己廊蜒,他們只是感情好,可當我...
    茶點故事閱讀 67,488評論 6 392
  • 文/花漫 我一把揭開白布溅漾。 她就那樣靜靜地躺著山叮,像睡著了一般。 火紅的嫁衣襯著肌膚如雪添履。 梳的紋絲不亂的頭發(fā)上屁倔,一...
    開封第一講書人閱讀 51,365評論 1 302
  • 那天,我揣著相機與錄音暮胧,去河邊找鬼锐借。 笑死,一個胖子當著我的面吹牛往衷,可吹牛的內(nèi)容都是我干的钞翔。 我是一名探鬼主播,決...
    沈念sama閱讀 40,190評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼席舍,長吁一口氣:“原來是場噩夢啊……” “哼布轿!你這毒婦竟也來了?” 一聲冷哼從身側響起来颤,我...
    開封第一講書人閱讀 39,062評論 0 276
  • 序言:老撾萬榮一對情侶失蹤汰扭,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后脚曾,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體东且,經(jīng)...
    沈念sama閱讀 45,500評論 1 314
  • 正文 獨居荒郊野嶺守林人離奇死亡本讥,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,706評論 3 335
  • 正文 我和宋清朗相戀三年鲁冯,在試婚紗的時候發(fā)現(xiàn)自己被綠了色查。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,834評論 1 347
  • 序言:一個原本活蹦亂跳的男人離奇死亡跨扮,死狀恐怖验毡,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情晶通,我是刑警寧澤,帶...
    沈念sama閱讀 35,559評論 5 345
  • 正文 年R本政府宣布一也,位于F島的核電站喉脖,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏树叽。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,167評論 3 328
  • 文/蒙蒙 一须误、第九天 我趴在偏房一處隱蔽的房頂上張望仇轻。 院中可真熱鬧奶甘,春花似錦、人聲如沸臭家。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,779評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽你踩。三九已至讳苦,卻和暖如春吩谦,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背式廷。 一陣腳步聲響...
    開封第一講書人閱讀 32,912評論 1 269
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留蝗肪,地道東北人。 一個月前我還...
    沈念sama閱讀 47,958評論 2 370
  • 正文 我出身青樓穗慕,卻偏偏與公主長得像妻导,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子术浪,可洞房花燭夜當晚...
    茶點故事閱讀 44,779評論 2 354

推薦閱讀更多精彩內(nèi)容