android 項目三種布局

來源:互聯網
上載者:User

標籤:primary   html   near   wrap   apk   rac   組件   class   pad   

首先要明白的是其一android中的組件使用的是盒子模型,與html標籤一樣有margin和padding屬性,但是名字不一樣。其二Android在布局中不使用px為單位,而是使用dp為長度單位,sp為字型大小單位

一、 線性布局LineaLayout

  值得注意的是LinearLayout標籤有一個必要屬性android:orientation,用來指示組件是水平展開(horizontal)還是垂直展開(vertical)。下面給出一個LinearLayout的基本使用

  1.水平展開--horizontal

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="horizontal"><!--水平展開-->    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        android:background="@color/colorAccent"        android:text="這是文字1!"        android:textSize="25sp"/>    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        android:background="@color/colorPrimary"        android:text="這是文字2"        android:textSize="20sp"/></LinearLayout>

  預覽圖:可以看出第二個TextView在第一個TextView的右方

  2. 垂直展開--vertical

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:orientation="vertical"><!--垂直展開-->    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        android:background="@color/colorAccent"        android:text="這是文字1!"        android:textSize="25sp"/>    <TextView        android:layout_width="wrap_content"        android:layout_height="wrap_content"        android:layout_margin="10dp"        android:background="@color/colorPrimary"        android:text="這是文字2"        android:textSize="20sp"/></LinearLayout>

 

  預覽圖:可以看出第二個TextView在第一個TextView的下方

 二、

android 項目三種布局

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.