课堂笔记:Android UI控件
常用的UI控件:
- TextView:
mathch_parent:表示讓當(dāng)前控件大小能夠剛好包含里面的內(nèi)容,也就是由空間內(nèi)容決定當(dāng)前空間的大小
android:layout_width:指定控件的寬帶
android:layout_height:指定控件的高度
三個(gè)可選值:
match_parent、fill_parent:和父布局大小一樣,推薦使用match_parent
warp_content:剛好包裹里面的內(nèi)容
同時(shí)也可以指定一個(gè)固定的值
問(wèn)題是:有時(shí)會(huì)在不同的手機(jī)屏幕上出現(xiàn)適配的問(wèn)題
可以使用android:gravity來(lái)指定文字的對(duì)其方式
修改文字的大俠和顏色
android:textSize:修改文字的大小(單位sp)
android:textColor:設(shè)置文字的大小
- Button
是和用戶進(jìn)行交互的一個(gè)重要的按鈕組件
android:textAllCaps="false"對(duì)其進(jìn)行設(shè)置
<Buttonandroid:layout_width="match_parent"android:layout_height="wrap_content"android:id="@+id/button_first"android:textAllCaps="false"android:text="to first"/>還可以設(shè)置監(jiān)聽(tīng)器:
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);}});} }每次的點(diǎn)擊事件都會(huì)執(zhí)行監(jiān)聽(tīng)器中的onClick()方法
只需要再監(jiān)聽(tīng)器中實(shí)現(xiàn)自己的邏輯
同時(shí)還可以實(shí)現(xiàn)接口的方法來(lái)實(shí)現(xiàn)開(kāi)進(jìn)行注冊(cè)
- EditText
用于和用戶進(jìn)行交互,允許用戶向控件中輸入和編輯內(nèi)容
并可以再程序中對(duì)這些內(nèi)容 進(jìn)行處理
android:hint:是提示的內(nèi)容,點(diǎn)擊輸入內(nèi)容之后就hi消失
對(duì)輸入的文本內(nèi)容有一個(gè)限制
使用android:maxLines:數(shù)值
對(duì)其最大行進(jìn)行限制
- ImageView
主要用于再界面上展示圖片
可以使程序的頁(yè)面變得更加豐富多彩
注意:圖片通常是放在drawable開(kāi)頭的目錄下
ProgressBar
用于在界面上顯示一個(gè)進(jìn)度條
表示程序加載一些數(shù)據(jù)
總結(jié)
以上是生活随笔為你收集整理的课堂笔记:Android UI控件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: c++ 写入文件_常见数据库写入Webs
- 下一篇: Android OTG 连接单反相机,相