標籤:android 布局
昨天千鋒公司來我們學校進行培訓一周,順便我也把android UI複習一遍
昨天詳細講解了textview以及Activity的一些介紹
先看xml:
<!-- Layout 按照一定方式排列組建LinearLayout 線性布局按照直線的方式排列UI組建xmlns:android 命名空間 相當於importandroid:layout_width 寬度android:layout_height 高度match_parent 為可以使用的最大值 填充父組件 fill_parentandroid:orientation 組建的相片順序 垂直:vertical 水平:horizontal --><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/LinearLayout1" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <!-- 顯示文字組件 android:text 顯示的文字 wrap_content 包裹內容 能完全顯示內容的大小 android:background="#F00" 背景顏色 #RGB 200dp 與像素無關單位 適應多種螢幕,保證在不同螢幕上顯示效果相同 @資源引用 類似於R。class + 添加 會在添加之前判斷,是否存在,如果存在不添加,如果不存在才添加 往R類id子類中添加 textView1 android:id 標識UI組件 --> <TextView android:id="@+id/textview1" android:layout_width="fill_parent" android:layout_height="fill_parent" android:background="#F00" android:textSize="30dp" android:text="@string/hello_world" /></LinearLayout>
主Activity中尋找了下控制項:
package com.example.test;import android.app.Activity;import android.os.Bundle;import android.view.Menu;import android.view.View;import android.widget.TextView;/** * Activity * 四大組建之一 * 用來顯示應用介面, 可以與使用者進行互動 * 點擊,拖動。。 * @author LiCheng * */public class MainActivity extends Activity { //從Activity繼承過來的方法//當Activity建立調用時調用的方法//main@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);//設定內容視圖//設定Activity顯示的介面//索引//R.layout.activity_main//res/layout/activity_main.xml//Ctrol+D 刪除一行setContentView(R.layout.activity_main); //找到組建 View textView=findViewById(R.id.textview1); //強制類型轉換 TextView tv=(TextView)textView; //修改內容 設定文本 tv.setText("呵呵"); /** * 快速鍵: * 1. ctrl+shift+o 導包 * 2. ctrl+ 1 萬能快速鍵 * 3. alt+ / 代碼提 */}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}