Android開發筆記(2)——ViewGroup

來源:互聯網
上載者:User

標籤:相容   最新版   程式   vertica   studio   tor   wrap   and   shmall   

一、ViewGroup

 1、ViewGroup的意義——整合Layout多個不同View,並對其進行位置排列

 

2、ViewGroup種類

Linear Layout  簡單直接的布局格式,只允許水平放置 / 垂直放置

Relative Layout  複雜生動的布局格式,可根據父 / 子View相對位置來設定

 

 

二、Layout

  • Anroid URL標記

         xmlns:android=”http://schemas.android.com/apk/res/android”

       在XML檔案根視圖開合標記中添加XML命名空間,和“android:”表示屬於android屬性。

 

  • 布局參數

       眾多屬性裡,涉及background、text、textSize均由TextView風格化視圖處理

       涉及layout_width\layout_height\layout_above為布局參數,由ViewGroup統一管理。

  • Linear Layout

1)   只允許整個布局全水平 / 全垂直放置

       android: orientation= ”vertical”

       android: orientation= ”horziontal”

       2)      如何在不同裝置螢幕上實現視圖等分?

           固定長寬×

           layout_weight設定每個View的長寬權重,等比例放置

規則:

1)      配置固定長寬、wrap_contentView

2)      配置layout_weight

android:layout_width=”0dp”

android:layout_weight=“1”

3)      計算剩餘空間

4)      分配剩餘空間(全部佔滿

a)      當有且僅有一個View設定權重,無論值大小,均佔滿

b)      當兩個及以上View設定權重,按照設定數值,等比例分配空間

c)      特殊情況:等分——保證所有View權重值相等

5)      當weight=0 / 不設定(預設為0)時,View大小不改變

 

 

  •   Relative Layout

1)    相對於Parent View

           整個視圖貼合四條邊,設定對齊屬性,true / false

android : layout_alignParentTop

android : layout_alignParentBottom

android : layout_alignParentLeft

android : layout_alignParentRight

      所有加入relative layoutView預設放置在左上方

 

    2)  置中顯示

android : centerHorizontal = “ true”

android : centerVertical = “true”

        結合其他屬性,即可確定以上8個紅星位置

    3)   View ID命名

       錨定位置:無論其他元素如何變化,保持固定位置的View,相對於Child View設定,需要對每個View進行命名(設定ID)

           定義(第一次使用) android : id = “@ + id / ben_text_view”

           重複使用:@ id / ben_text_view

    4)  相對於Child View

android : layout_toLeftof = “@ id / ben_text_view”

android : layout_toRightof

android : layout_above

android : layout_below

 

 

  • Padding & Margin

    1)    兩者區別

      a)      PaddingTextView處理,強行擴大原面積

      b)      MarginParent ViewGroup處理,保持原View大小,向外設定“禁飛區

 

    2)    屬性設定

      四周 android : padding / android : margin

      單獨(進入單獨設定後,為設定參數預設為0)

android : paddingLeft / Right / Top / Bottom

android : marginLeft / Right / Top / Bottom

 

 

三、Android Studio安裝 & 使用

    1)  Android Studio 是特定為開發Android apps應用的平台,需要先安裝Java開發套件(Java Development Kit

    2)  Android Project

           Domain——填寫公司網域名稱或者個人網域名稱

           Package name —— 倒置“Domain + appname ”,是識別這個app的唯一標識

           Android版本——不同版本以糖果甜點來命名

           低版本可相容高版本,高版本不支援低版本平台,例如採用最新的Marshmallow,只能保證使用最新版本的4.7%使用者下載

             常採用 IcecreamSandwich,保證97.4%使用者可以下載

 

    3)  實機演練:Android Phone開啟設定,點擊About mobile7次可開啟Developer Mode

      ——如果是WINDOWS,需要下載OEM USB Drivers

    4)  電腦類比:使用Android Emulator

      ——WINDOW 使用Virtual Devices ,需要系統支援Virtual Technology,並在BIOS中開啟

 

 

l  生日賀卡實踐演練

Android Studio視圖配置

 

 

程式設計流程

 

Android Studio視圖配置

 

 

申明:

1、本筆記為文字及圖片均為個人原創,請勿轉載

2、Android開發課程於2017年4年參與GoogleDeveloper進行學習,

筆記原版http://www.studyjamscn.com/thread-19454-1-1.html

 

Android開發筆記(2)——ViewGroup

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.