Android的布局和Intent筆記和常用執行個體

來源:互聯網
上載者:User

今天開始接觸和熟悉Android上層應用,學海無涯,回頭是岸 -_-||

三種常見布局方法:Linearlayout(線性布局)、TableLayout?(表格版面配置)、Relative Layout(相對布局)。

相對布局比起前面兩種布局方法而言更隨意,使用者可以將控制項放在自己所希望的任何位置。

在LinearLayout和TableLayout中常見的指令有

android:id——控制項指定相應ID

android:text——控制項中顯示文字。注意盡量使用Strings.xml

android:gravity——控制項中文字基本位置,如center、left、right、center_horizontal等。

android:textsize——控制項中字型大小,單位為pt。

android:background——控制項背景色

android:width——控制項寬度

android:height——控制項高度

android:padding——空間內邊距,指控制項當中內容到空間的距離。其中有android:padding_left、android:padding_right等。

android:siglelise——如果設定為真,控制項內容將在同一行顯示。

android:margin——外邊距。

相對布局Relative Layout

android:Layout_above——將控制項底部至於給定控制項之上

android:Layout_below——將控制項頂部至於給定控制項之下

android:Layout_toleftof——將控制項左邊緣至於給定控制項右邊

android:Layout_toRightof——將控制項左邊緣至於給定控制項右邊

android:Layout_alignBaseline——將控制項的Baseline與指定控制項的Baseline對齊。

android:Layout_alignleft——將控制項的左邊與指定控制項的左邊對齊。

android:Layout_alignright——將控制項的右邊與指定控制項右邊對齊。

android:Layout_alignTop——將控制項的頂部與指定控制項頂部對齊。

android:Layout_alignParentBottom——為真,控制項與父控制項對齊。

android:Layout_centerHorizontal——為真,空間被至於水平方向中央。

android:Layout_centerinParent——為真,至於父控制項水平/垂直方向中央。

android:Layout_centervertural——被置於垂直方向中央。

intent-filter

1 android.intent.action.MAIN決定應用程式最先啟動的Activity。

2 android.intent.category.LAUNCHER決定應用程式是否顯示在程式列表裡。

intent調用應用程式

例子: 調用Google瀏覽器

Uri uri = Uri.parse("http://www.android123.com.cn");

Intent it = new Intent(Intent.ACTION_VIEW,uri);

startActivity(it);

常用的應用程式調用

顯示web網頁:

1. Uri uri = Uri.parse("http://www.android123.com.cn");

2. Intent it = new Intent(Intent.ACTION_VIEW,uri);

3. startActivity(it);

顯示google地圖:

1. Uri uri = Uri.parse("geo:38.899533,-77.036476");

2. Intent it = new Intent(Intent.Action_VIEW,uri);

3. startActivity(it);

聯繫我們

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