Android studio的UI组件
生活随笔
收集整理的這篇文章主要介紹了
Android studio的UI组件
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
1.文本框組件
?掌管文字大小,文字來(lái)源,文字是否以行的形式顯示,對(duì)齊方式居中
9patch圖片拉伸不變形,需要放在drawable中
<TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:textSize="30dp"android:text="@string/demo1"android:singleLine="true"android:gravity="center"/>?
2.編輯框組件
掌管一些可輸入的文字框,這里可以給用戶提供輸入
<EditTextandroid:layout_width="match_parent"android:layout_height="wrap_content"android:hint="請(qǐng)輸入密碼"android:inputType="numberPassword"/>?在編輯框內(nèi)繪制圖像屬性:(相對(duì)于文字的方向)
android:drawableLeft=""左側(cè)android:drawableStart=""左側(cè)android:drawableBottom=""底部android:drawableRight=""右側(cè)android:drawableEnd=""右側(cè)android:drawableTop=""頂部 搭配android:drawablePadding=""配合內(nèi)邊距3.普通按鈕組件
文字按鈕:很簡(jiǎn)單,和上面組件的屬性差不多,一樣是設(shè)置寬高,設(shè)置text文本內(nèi)容<Button>
圖片按鈕:區(qū)別如下<ImageButton/>
android:src="@資源名字"單選按鈕:可以設(shè)置單選的內(nèi)容,checked是默認(rèn)選中的意思
<RadioButtonandroid:id="@+id/rb_1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/btn2"android:text="男"android:checked="true"/>有時(shí)候不止一個(gè)單選按鈕,所以就需要單選按鈕組的出現(xiàn)<RadioGroup><RadioButton>......</RadioGroup>
<RadioGroupandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_below="@+id/btn2"><RadioButtonandroid:id="@+id/rb_1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="男"android:checked="true"/><RadioButtonandroid:id="@+id/rb_2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="女"/></RadioGroup>設(shè)置組的java監(jiān)聽(tīng)器,點(diǎn)擊男的單選框會(huì)顯示男,點(diǎn)擊女的單選框會(huì)顯示女
RadioGroup rg= (RadioGroup) findViewById(R.id.rg_1);rg.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {RadioButton rb= (RadioButton) findViewById(checkedId);rb.getText();Toast.makeText(DemoMainActivity.this, "性別:"+rb.getText(), Toast.LENGTH_SHORT).show();}});?復(fù)選框按鈕:
<CheckBoxandroid:id="@+id/cb_1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="人類"android:layout_below="@+id/bt3"/><CheckBoxandroid:id="@+id/cb_2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="人"android:layout_below="@+id/cb_1"/><CheckBoxandroid:id="@+id/cb_3"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="類"android:layout_below="@+id/cb_2"/>?
?
?
總結(jié)
以上是生活随笔為你收集整理的Android studio的UI组件的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 计算机考试网络应用题一定要做到ie浏览器
- 下一篇: 夸克浏览器怎么安装脚本_广告看烦了?别砸