日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

课堂笔记:Android UI控件

發布時間:2023/12/8 Android 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 课堂笔记:Android UI控件 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

常用的UI控件:

  • TextView:
<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="Hello World!"app:layout_constraintBottom_toBottomOf="parent"app:layout_constraintLeft_toLeftOf="parent"app:layout_constraintRight_toRightOf="parent"app:layout_constraintTop_toTopOf="parent" />

mathch_parent:表示讓當前控件大小能夠剛好包含里面的內容,也就是由空間內容決定當前空間的大小
android:layout_width:指定控件的寬帶
android:layout_height:指定控件的高度
三個可選值:
match_parent、fill_parent:和父布局大小一樣,推薦使用match_parent
warp_content:剛好包裹里面的內容
同時也可以指定一個固定的值
問題是:有時會在不同的手機屏幕上出現適配的問題
可以使用android:gravity來指定文字的對其方式

<TextViewandroid:id="@+id/text_view"android:text="tViews"android:gravity="center"android:layout_width="match_parent"android:layout_height="wrap_content" />

修改文字的大俠和顏色

android:textSize:修改文字的大小(單位sp)

android:textColor:設置文字的大小

  • Button
    是和用戶進行交互的一個重要的按鈕組件
<Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/button_first"android:text="to first"/><Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/button_second"android:text="to second"/>

android:textAllCaps="false"對其進行設置

<Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/button_first"android:textAllCaps="false"android:text="to first"/>

還可以設置監聽器:

public class FirstActivity extends AppCompatActivity {@Overrideprotected void onCreate(final Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.first_layout);Button first = (Button) findViewById(R.id.button_first);first.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {Intent intent = new Intent(FirstActivity.this,SecondActivity.class);startActivity(intent);}});} }

每次的點擊事件都會執行監聽器中的onClick()方法
只需要再監聽器中實現自己的邏輯
同時還可以實現接口的方法來實現開進行注冊

  • EditText
    用于和用戶進行交互,允許用戶向控件中輸入和編輯內容
    并可以再程序中對這些內容 進行處理
<EditTextandroid:id="@+id/edit_text"android:hint="請輸入賬戶"android:layout_width="match_parent"android:layout_height="wrap_content"/>

android:hint:是提示的內容,點擊輸入內容之后就hi消失
對輸入的文本內容有一個限制
使用android:maxLines:數值
對其最大行進行限制

  • ImageView
    主要用于再界面上展示圖片
    可以使程序的頁面變得更加豐富多彩
    注意:圖片通常是放在drawable開頭的目錄下
android:src:給ImageView指定一張圖片<ImageViewandroid:id="@+id/image_view"android:src="@drawable/image"android:layout_width="wrap_content"android:layout_height="wrap_content" />

ProgressBar
用于在界面上顯示一個進度條
表示程序加載一些數據

<ProgressBarandroid:id="@+id/progress_bar"android:layout_width="match_parent"android:layout_height="wrap_content" />進度條旋轉表示程序再加載數據//數據加載完成之后 //可使用android:visibility進行指定控件的可見性 //三個值:visible(默認)、invisible、gone //分別表示:可見的、不可見、不僅不可見而且還不占用屏幕空間 //實現點擊按鈕進行狀態轉換 //可見--不可見--可見

總結

以上是生活随笔為你收集整理的课堂笔记:Android UI控件的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。