何为 .9图?
图片应用到各个不同的分辨率的组件中,会造成图片失真变形。
## 制作图的工具 ##
- Android Studio 安装目录下的SDK文件夹内tools文件夹内的draw9path.bat
- 当前2.3.3版本吧工具加入到了界面中
按钮点击事件
1、 采用系统提供的点击事件,我接下来用一个按钮做示范。
```<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="计算"
android:onClick="calculate" <!--给按钮点击属性设定一个名字,过会要用-->
android:id="@+id/bt_acti_js" <!--按钮的id通过它可以找到按钮-->
/>```
//现在去java页面编写触发事件代码
package com.example.basiccontrolfive;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.被调用的xml文件名);
}
//第一种点击事件,编写一个有参无返回方法,方法名和刚才按钮的点击事件名一样,其他,按照如下规定,禁止变更!!
public void calculate(View view){
//编写触发后效果代码
}
}
2、 第二种点击触发事件
`
package com.example.basiccontrolfive;
public class ComprehensiveActivity extends AppCompatActivity{
@verride
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.homework_comprehensive);
//首先从R类中,通过ID找到需要设定点击事件的组件
buttonOne = (Button) findViewById(R.id.bt_sive_register);
//需要设定事件的组件对象,设定一个事件,参数为,建立一个组件事件
buttonOne.setOnClickListener(new View.OnClickListener() {
//遍写代码
}
}
`
RadioButton(单选)、给单选组设定OnCheckedChangeListener事件(可以知晓,是哪个单选被选中了)
想要实现单选必须的放入,单选组中
RadioButton相关属性
android:button=”@null” //不显示单选的那个圆珠
android:drawableTop=”@drawable/weixin_radio” 在单选之上设置其他图片之类的
RadioGroup.getCheckedRadioButtonId ();–获取选中按钮的id
RadioGroup.clearCheck ();//—清除选中状态
RadioGroup.check (int id);//—通过参入选项id来设置该选项为选中状态如果传递-1作为指定的选择标识符来清除单选按钮组的勾选状态,相当于调用clearCheck()操作
addView (View child, int index, ViewGroup.LayoutParams params);//—使用指定的布局参数添加一个子视图
//参数 child 所要添加的子视图 index 将要添加子视图 的位置 params 所要添加的子视图的布局参数setOnCheckedChangeListener (RadioGroup.OnCheckedChangeListener listener); //–一个当该单选按钮组中的单选按钮勾选状态发生改变时所要调用的回调函数
- RadioButton.getText();//获取单选框的值
//此外,RadioButton的checked属性设置为true,代码里调用RadioButton的check(id)方法,不会触发onCheckedChanged事件
代码示例
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/rg_acti_dx" //单选组