Androld总结
总结
``` nix
1.<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Please choose a flower Please choose a flower"
android:textSize="24sp"
android:textColor="#0000cd"
android:singleLine="true"
android:ellipsize="marquee"
android:focusableInTouchMode="true"
android:focusable="true"/>
跑马灯 这都是在网上找的 当时遇到的问题就是文字不能跑起来 查了之后才知道是字数的问题 于是就打了两遍
2..<ImageVi
ew android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@mipmap/ic_launcher"/>
用imageview来添加图片 androld src 选择你需要的图片
3.<CheckBox
android:id="@+id/chk_math"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="高等数学"/>
<CheckBox
android:id="@+id/chk_java"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Java"/>
多选按钮 要点是需要给他们id
4. <RadioGroup
android:id="@+id/rg_hua1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="@+id/rbtn_mudan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="牡丹"
android:textSize="20sp"/>
<RadioButton
android:id="@+id/rbtn_yueji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="月季"
android:textSize="20sp"/>
<RadioButton
android:id="@+id/rbtn_lanhua"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="兰花"
android:textSize="20sp"/>
</RadioGroup>
使用RadioGroup RadioButton 来创建两行三列的单选按钮。当时在写这个作业的时候创建了两个RadioGroup 最后就遇到了每行都可以点一个按钮,不知道怎么把前一行点过的按钮去掉,这个问题现在还不会。
5.public class MainActivity extends AppCompatActivity {
private ImageView imgHua;
private RadioGroup rgHua1;
private RadioButton rbtnMudan;
private RadioButton rbtnYueji;
private RadioButton rbtnLanhua;
private RadioGroup rgHua2;
private RadioButton rbtnQiangwei;
private RadioButton rbtnYinghuai;
private RadioButton rbtnHehua;
获取事件
6.protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imgHua=(ImageView)findViewById(R.id.img_hua);
rgHua1 = (RadioGroup) findViewById(R.id.rg_hua1);
rbtnMudan = (RadioButton) findViewById(R.id.rbtn_mudan);
rbtnYueji = (RadioButton) findViewById(R.id.rbtn_yueji);
rbtnLanhua = (RadioButton) findViewById(R.id.rbtn_lanhua);
rgHua2 = (RadioGroup) findViewById(R.id.rg_hua2);
rbtnQiangwei = (RadioButton) findViewById(R.id.rbtn_qiangwei);
rbtnYinghuai = (RadioButton) findViewById(R.id.rbtn_yinghua);
rbtnHehua = (RadioButton) findViewById(R.id.rbtn_hehua);
设置监听事件
6.public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()){
case Menu.FIRST + 1:
case Menu.FIRST + 2:
case Menu.FIRST + 3:
Toast.makeText(this,item.getTitle().toString()+"菜单被击中",Toast.LENGTH_LONG).show();
break;
case R.id.item_about:
//创建一个普通的Dialog(让关于可以弹出一个对话框)
AlertDialog.Builder builder = new AlertDialog.Builder(MeiActivity.this);
builder.setTitle("关于");
builder.setIcon(R.mipmap.ic_launcher);
builder.setMessage("版本为1.0");
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
//把dialog关闭(只关dialog本身,不写也会被关闭)
dialog.dismiss();
//Dialog所在的Activity被关闭(关闭界面本身)
MeiActivity.this.finish();
}
});
builder.setNegativeButton("取消",new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface,int i) {
}
});
builder.setNegativeButton("退出",null);
//创建并显示
builder.create().show();
break;
}
return super.onOptionsItemSelected(item);
创建对话框
总结:通过这段时间的学习了解到一些androldstudio的简单用法
1.要在xml中设计界面 用到一些简单的控件如TextView 显示文本信息
imageview用来显示图片 radiogroup单选按钮 checkbox 复选框等等一些控件。
2.在java中需要做的事定义相关组件,然后获取组件,最后设置监听事件
这里最关键的是id要和xml中的一样