Android基礎(chǔ)控件TextView/EditText/Button和ImageView認(rèn)識

今天我們來和大家一起認(rèn)識Android幾個最基本的控件,分別是顯示文本的TextView、用于輸入額EditText、用于點擊的Button和顯示圖像的ImageView,那為了更好地呈現(xiàn)這幾個控件了,我們先認(rèn)識一下Android的一種最簡單的布局——線性布局

一、線性布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    android:background="#0f0"
    >
</LinearLayout>

二、文本控件TextView

   <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="這是用于顯示文字的控件"
     />

三 、輸入控件

    <EditText
        android:layout_width="match_parent"
        android:layout_height="40dp"
        android:hint="請輸入文字"
        />

四、按鈕控件Button

  <Button
        android:layout_width="match_parent"
        android:layout_height="48dp"
        android:text="這是個按鈕"/>

五 圖片控件ImageView

    <ImageView
        android:id="@+id/iv_g1"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:background="#888"
        >

上面我沒放圖片,考慮到各位那邊不一定有那張圖片,你們可以添加自己圖片測試

六、總結(jié)

Android的控件都繼承于View,View都有一下幾個常用屬性,也都可以給View設(shè)置點擊事件。

  1. 控件的寬
android:layout_width="match_parent"
  1. 控件的高
android:layout_height="40dp"
  1. 背景顏色
 android:background="#ff0000"
  1. id
 android:id="@+id/iv_g1"

同步b站視頻

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容