View中有一个公用属性visibility:
gone:将控件隐藏,并且不再占用布局控件,但是依然会加载到内存中。
invisible:将控件隐藏,但依然占用布局控件,也会被加载到内存中。
visible:将控件设置为显示。
1、ImageView
a、background:如果设置图片,则将图片拉伸充满整个容器背景。
b、src:按照scaleType设置模式进行图片的摆放。
c、scaleType:
c.1、fitXY:将图片拉伸至该ImageView的宽度和高度。
c.2、fitStart:将图片等比例缩放到最大区间,然后放置于ImageView的最开 始处。
c.3、fitEnd:同理于fitStart。放置于末尾处。
c.4、fitCenter:同理于fitStart。放置于中间。
c.5、center:图片不缩放,直接将图片放置于ImageView中心位置。
c.6、centerCrop:按照ImageView的最大边界缩放,超出部分裁出,放置于 ImageView中。
c.7、centerInside:等同于fitCenter
2、EditText
a、文本输入框
b、这就是一个可以输入内容的TextView
c、关于inputType参数属性的使用
android:inputType=”none”–输入普通字符
android:inputType=”text”–输入普通字符
android:inputType=”textCapCharacters”–输入普通字符
android:inputType=”textCapWords”–单词首字母大小
android:inputType=”textCapSentences”–仅第一个字母大小
android:inputType=”textAutoCorrect”–前两个自动完成
android:inputType=”textAutoComplete”–前两个自动完成
android:inputType=”textMultiLine”–多行输入
android:inputType=”textImeMultiLine”–输入法多行(不一定支持)
android:inputType=”textNoSuggestions”–不提示
android:inputType=”textUri”–URI格式
android:inputType=”textEmailAddress”–电子邮件地址格式
android:inputType=”textEmailSubject”–邮件主题格式
android:inputType=”textShortMessage”–短消息格式
android:inputType=”textLongMessage”–长消息格式
android:inputType=”textPersonName”–人名格式
android:inputType=”textPostalAddress”–邮政格式
android:inputType=”textPassword”–密码格式
android:inputType=”textVisiblePassword”–密码可见格式
android:inputType=”textWebEditText”–作为网页表单的文本格式
android:inputType=”textFilter”–文本筛选格式
android:inputType=”textPhonetic”–拼音输入格式
android:inputType=”number”–数字格式
android:inputType=”numberSigned”–有符号数字格式
android:inputType=”numberDecimal”–可以带小数点的浮点格式
android:inputType=”phone”–拨号键盘
android:inputType=”datetime”
android:inputType=”date”–日期键盘
android:inputType=”time”–时间键盘
3、CheckBox
a、重点:监听事件的设置:setOnCheckedChangeListener
例子:QQ登录上 记住密码与自动登录之间逻辑关系的设置
两个CheckBox布局:
<CheckBox
android:id="@+id/checkbox_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="20dp"
android:checked="false"
android:text="记住密码"
/>
<CheckBox
android:id="@+id/checkbox_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="20dp"
android:checked="false"
android:text="自动登录"
/>
checkbox1 = (CheckBox) findViewById(R.id.checkbox1);
checkbox2 = (CheckBox) findViewById(R.id.checkbox2);
OnCheckedChangeListener occl = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
switch (buttonView.getId()) {
case R.id.checkbox1:
if(checkbox2.isChecked() && !isChecked){
checkbox2.setChecked(false);
}
break;
case R.id.checkbox2:
if(isChecked){
checkbox1.setChecked(true);
}
break;
}
}
};
checkbox1.setOnCheckedChangeListener(occl);
checkbox2.setOnCheckedChangeListener(occl);
4、RadioGroup/RadioButton
a、即单选模型控件
b、RadioGroup设置监听:RadioGroup.OnCheckedChangeListener
c、onCheckedChanged(RadioGroup group, int checkedId)
参数中:
前者:你所点击的RadioButton所在的组
后者:你所点击的RadioButton的id。
布局文件:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="请选择性别:"
android:textColor="#2c2c2c"
android:textSize="25sp" />
<RadioGroup
android:id="@+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:contentDescription="请选择性别:"
android:orientation="vertical" >
<RadioButton
android:id="@+id/radiobutton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="男" />
<RadioButton
android:id="@+id/radiobutton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="女" />
<RadioButton
android:id="@+id/radiobutton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="其他性别" />
</RadioGroup>
</LinearLayout>
radiogroup = (RadioGroup) findViewById(R.id.radiogroup);
radiogroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
RadioButton radioButton = (RadioButton) findViewById(checkedId);
Toast.makeText(MainActivity.this, radioButton.getText(), 0).show();
}
});