Android User Interface1:View&移動終端軟件開發課程&StudyAccount2 2018.9.11

###1.View
Android所有控件全都繼承自View類,(需要在.java文件中導入android.view.View;)具有所有的View屬性。
視圖的繼承關係

####1.1TextView:用來顯示文本信息
ex:

 <TextView
        android:id="@+id/textView1"//表示該控件的id,在佈局文件中或者代碼中被引用
        android:layout_width="match_parent"//填滿父控件
        android:layout_height="wrap_content"//裹住內容,不設置具體值
        android:text="@string/easy_text"
        android:gravity="center_vertical"//設置文本縱向居中
        android:paddingLeft="5dip"//設置內邊距
        android:layout_marginTop="5dip"//設置外邊距
        android:textColor="@color/colorPrimaryDark"/>

#####wrap_content&wrap_content&fill_parent的區別:

  • wrap是根據容器內的東西決定組件的大小,比如一個按鈕,按鈕中的字體大,那麼這個按鈕就大,字體小那麼相應的按鈕就會小些。
  • match的話是指“填充滿”父容器。但是他跟fill_parent是不一樣的,fill是真的填滿,沒有條件。而match的話有自動調整的功能
    #####android:text=”@string/easy_text”—— android:textColor=”@color/colorPrimaryDark”
  • 表示顯示的文本信息是strings.xml中name=easy_text的內容,文本顏色是colors.xml中name=colorPrimaryDark的顏色
  • 另一種寫法是android:text=”你們好”;android:textColor=”#303F9F”(不推薦)
    1
    2
    ####1.2 EditView:用來編輯輸入的文本信息
    <EditText
        android:id="@+id/editText2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="密碼"//表示在輸入之前的提示
        android:SingleLine="ture"//文本輸入框不可換行輸入,只能在一行內輸入文本
        android:inputType="textPassword"
        />

#####android:inputType=”textPassword”

  • 表示輸入框是用來輸入密碼的,輸入的文本會自動變爲“.”,起到隱藏用戶密碼的作用。
  • 另一種寫法是android:password=”true”
    ####1.3Button:按鈕組件
    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="ButtonClick"
        android:text="登錄" />

#####android:onClick=”ButtonClick”

  • 該屬性在源代碼中設置一個ButtonClick方法,作爲該Button的點擊監聽方法
  • 實現監聽還可以調用findViewById(int id)找到該Button,後續文章會應用的
    3

1.4ImageView:展示圖片

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:scaleType="center"//表示圖片以何種形式填充到View對應的矩形區域
        android:src="@drawable/cat" />//設置填充的圖片
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章