Android04之CheckBox和ImageView

本文详细介绍了Android中两种常用的UI控件:CheckBox和ImageView。对于CheckBox,讲解了其常用属性、自定义样式和监听事件。对于ImageView,讨论了其属性及如何加载网络图片,特别提到了使用Glide库进行图片加载的方法。
摘要由CSDN通过智能技术生成

上次我们介绍了两种常用的UI控件,分别是EditText和RadioButton,不清楚用法的可以查看我的上一次博客,链接为https://blog.csdn.net/chenpeixing361/article/details/89054256。这一次我们我们继续介绍两种常用的控件,分别是CheckBox和ImageView。

CheckBox

checkbox也就是复选框的意思,我们选择一项或者多项标签。这里我们主要讲解以下内容:①常用属性;②自定义样式;③监听事件。我们紧接着之前的博客内容进行拓展,在activity_main.xml中添加两个按钮,代码如下:

  <Button
        android:id="@+id/btn_checkbox"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/check_box"
        android:textAllCaps="false"/>
<Button
        android:id="@+id/btn_image_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/image_view"
        android:textAllCaps="false"/>

我们这里把介绍ImageView的按钮也顺便添加进去,然后我们新建两个Activity类,类名分别是CheckBoxActivity和ImageViewActivity。我们在MainActivity中,设置两个界面跳转事件,代码如下:

 Button btnCheckBox = findViewById(R.id.btn_checkbox);
        btnCheckBox.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到CheckBox界面
                Intent intent = new Intent(MainActivity.this,CheckBoxActivity.class);
                startActivity(intent);
            }
        });

        Button btnImageView = findViewById(R.id.btn_image_view);
        btnImageView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //跳转到ImageView界面
                Intent intent = new Intent(MainActivity.this,ImageViewActivity.class);
                startActivity(intent);
            }
        });

我们在创建CheckBoxActivity类时,会附带创建一个activity_check_box.xml文件,该文件即代表该界面的布局,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="15dp">
    
    <TextView
        android:id="@+id/tv_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="你会哪些移动开发:"
        android:textColor="#000"
        android:textSize="20sp"
        android:layout_marginBottom="10dp"/>
    <CheckBox
        android:id="@+id/cb_1
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值