Android应用开发一课一得

本文介绍了作者在学习Android应用开发过程中的体验和收获,包括Android系统的基本概念、开源优势、历史沿革,以及常见的AndroidStudio控件如TextView、Button、EditText等的使用。此外,还提到了布局管理如LinearLayout、RelativeLayout和ConstraintLayout,并强调了Android开发的挑战性和实践的重要性。
摘要由CSDN通过智能技术生成

Android应用开发一课一得

1.引言

这学期,我们新开了一门课程android应用开发。在老师的介绍下,我们了解android的开发环境以及控件的功能。刚开始接触Android觉得既陌生又亲切,陌生。在于没有学过具体的开发软件,亲切在于它在界面开发上和wb也可以形成了相通的架构,更加方便。

通过一个学期的android学习,基本掌握了Android应用程序开发的一般流程。对常用控件基本掌握其用法,对其事件的监听方法也基本掌握。学习Android不仅是对前沿开发技术的了解,也是对编程知识的一次提升。

2.Android 概述

在这里插入图片描述

Android 是一个开源的,基于 Linux 的移动设备操作系统,如智能手机和平板电脑。Android 是由谷歌及其他公司带领的开放手机联盟开发的。
Android 提供了一个统一的应用程序开发方法,这意味着开发人员只需要为 Android 进行开发,这样他们的应用程序就能够运行在不同搭载 Android 的移动设备上。

Android 源代码是根据自由和开放源码软件许可证。谷歌发布的大部分代码遵循 Apache 许可证2.0版,Linux 内核的变化遵循 GNU 通用公共许可证版本2。

2.1Android 开发优势

1.开放源代码
2.众多开发者及强大的社区
3.不断增长的市场
4.国际化的 App 集成
5.低廉的开发成本
6.更高的成功几率
7.丰富的开发环境

2.2Android 的历史

Android 的代码名称现在从 A 排到了 L,分别是 Aestro, Blender, Cupcake, Donut, Eclair, Froyo, Gingerbread, Honeycomb, Ice Cream Sandwitch, Jelly Bean, KitKat and Lollipop。
在这里插入图片描述

3.学习内容(部分)

3.1android studio常见控件

1、TextView

 <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World!"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

2、Button(按钮)

<Button
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"/>

3、EditText(输入框)

 <EditText
       android:layout_width="match_parent"
       android:layout_height="wrap_content"/>

4、ImageView(显示图片)


 <ImageView
     android:layout_width="wrap_content"
     android:layout_height="match_parent"
     android:src="@drawable/咩"/>

在这里插入图片描述

6、AlertDialog(对话框)

// 创建对话框构造器
AlertDialog.Builder builder = new AlertDialog.Builder(this);

// 设置对话框的标题
builder.setTitle("提示");

// 设置对话框的消息内容
builder.setMessage("这是一个AlertDialog示例!");

// 设置对话框的图标(可选)
builder.setIcon(android.R.drawable.ic_dialog_alert);

// 设置对话框的确认按钮及其点击事件处理程序
// 点击确认按钮后,关闭对话框并执行相应操作
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // 执行确认操作的代码
        // 可以留空,不执行任何操作
    }
});

// 设置对话框的取消按钮及其点击事件处理程序
// 点击取消按钮后,关闭对话框并执行相应操作
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // 执行取消操作的代码
        // 可以留空,不执行任何操作
    }
});

// 创建并显示对话框
AlertDialog dialog = builder.create();
dialog.show();

7、ProgressDialog(进度对话框)

// 创建 ProgressDialog 对象
ProgressDialog progressDialog = new ProgressDialog(this);

// 设置显示的消息内容
progressDialog.setMessage("正在加载,请稍候...");

// 设置是否可以通过返回按钮或点击对话框外部取消对话框
progressDialog.setCancelable(false); // 设置为false表示不可取消

// 设置进度条的样式
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); // 设置为圆形进度条
//progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); // 设置为水平进度条

// 设置进度条的最大值(仅在STYLE_HORIZONTAL样式下生效)
//progressDialog.setMax(100);

// 设置进度条的当前进度值(仅在STYLE_HORIZONTAL样式下生效)
//progressDialog.setProgress(0);

// 设置点击对话框外部不可取消
//progressDialog.setCanceledOnTouchOutside(false);

// 设置对话框取消的事件监听器
progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
    @Override
    public void onCancel(DialogInterface dialog) {
        // 当对话框被取消时执行的操作
    }
});

8、RadioButton(单选框)
首先,在你的布局文件中添加 RadioButton

<RadioButton
    android:id="@+id/radio_button1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="选项1" />

<RadioButton
    android:id="@+id/radio_button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="选项2" />

然后,Activity 类中引用和处理 RadioButton

import android.widget.RadioButton;
import android.widget.RadioGroup;

// 在合适的地方定义 RadioButton 和 RadioGroup 对象
RadioButton radioButton1, radioButton2;
RadioGroup radioGroup;

// 在 onCreate 方法中找到对应的视图控件
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // 找到 RadioButton 和 RadioGroup 对应的视图控件
    radioButton1 = findViewById(R.id.radio_button1);
    radioButton2 = findViewById(R.id.radio_button2);
    radioGroup = findViewById(R.id.radio_group);

    // 设置 RadioGroup 的选择监听器
    radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
            // 从 RadioGroup 中获取选中的 RadioButton
            RadioButton selectedRadioButton = findViewById(checkedId);

            // 根据选中的 RadioButton 执行相应操作
            switch (selectedRadioButton.getId()) {
                case R.id.radio_button1:
                    // 执行选项1被选中时的操作
                    break;
                case R.id.radio_button2:
                    // 执行选项2被选中时的操作
                    break;
                // 添加更多的选项 ...
            }
        }
    });
}

9、checkbox(复选框)
首先,在你的布局文件中添加 Checkbox:

<CheckBox
    android:id="@+id/checkbox1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="选项1" />

<CheckBox
    android:id="@+id/checkbox2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="选项2" />

然后,在你的 Activity 类中引用和处理 Checkbox

import android.widget.CheckBox;
import android.widget.CompoundButton;

// 在合适的地方定义 Checkbox 对象
CheckBox checkbox1, checkbox2;

// 在 onCreate 方法中找到对应的视图控件
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // 找到 Checkbox 对应的视图控件
    checkbox1 = findViewById(R.id.checkbox1);
    checkbox2 = findViewById(R.id.checkbox2);

    // 设置 Checkbox 的选择监听器
    checkbox1.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // 执行选项1被选中时的操作
            } else {
                // 执行选项1被取消选中时的操作
            }
        }
    });

    checkbox2.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // 执行选项2被选中时的操作
            } else {
                // 执行选项2被取消选中时的操作
            }
        }
    });
}

3.2布局管理

1.LinearLayout(线性布局):
LinearLayout 是一种基本的布局容器,它将子视图按照水平或垂直方向进行线性排列。
2.RelativeLayout(相对布局):
RelativeLayout 是一种灵活的布局容器,它基于子视图之间的相对关系进行布局。
3.ConstraintLayout(约束布局):
ConstraintLayout 是一种灵活且性能优化的布局容器,它使用约束规则来定义子视图之间的关系。

4.学习总结

经过一个学期的学习,发现Android 应用开发是一个充满挑战但也充满乐趣的过程。学习 Android 应用开发需要坚实的基础知识、实际的实践经验和持续的学习精神。只有通过不断学习和实践,我们才能成为出色的 Android 开发者并创建出优秀的应用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值