Android---03---基礎1

來源:互聯網
上載者:User

標籤: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;}}




聯繫我們

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