Android Studio常用的UI控件

TextView 文本组件 显示简单的文本
ToggleButton 开关按钮
Edittext 文本组件
Button 按钮
CheckBox 复选框
Radiobutton+ RadioGroup 单选框
ImageVoew 图片
进度条组件 Progressbar的使用

一、布局设为线性布局

把根布局换位较为简单的线性布局Linelayout

在这里插入图片描述
选择convert view
在这里插入图片描述
选择线性布局
在这里插入图片描述

二、TextView

<TextView
    android:id="@+id/tv_title"
    android:text="这是TextView的内容"
    android:textSize="25sp"
    android:textStyle="bold"
    android:textColor="#ff0000"

    android:background="#999999"
    android:padding="10dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
  <!-- android:textAlignment="center"-->
    <!-- 文本尺寸的大小-->
    <!--bold 加粗 italic 斜体 normal 正常-->
    <!--字体的颜色 RGB的形式-->
    <!--字体文件末尾显示-->
    <!--背景颜色设置为灰色-->
    <!-- 边距大小-->

效果:
在这里插入图片描述

三、EditText

<EditText
    android:id="@+id/er_phone_Number"
    android:hint="请输入手机号码"
    android:inputType="phone"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />
    <!-- 输入数据的类型 -->

效果:
在这里插入图片描述

四、Button

<Button
    android:id="@+id/btn_submit"
    android:text="提交"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

效果:
在这里插入图片描述

五、ImageView

添加图片
复制一张图片(png格式)
在这里插入图片描述
转换为工程目录
在这里插入图片描述
Ctrl v 粘贴
在这里插入图片描述
改名字确认就可以

<ImageView
    android:id="@+id/iv_image"
    android:src="@drawable/lock"
    android:layout_gravity="center"
    android:background="@android:drawable/picture_frame"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
    <!-- source图片的来源-->
    <!--重心 图片方式居中-->
    <!-- 系统给的安卓的相框 -->

效果:
在这里插入图片描述

六、CheckBox

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <TextView
        android:text="爱好:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <CheckBox
          android:id="@+id/cb_foot"
          android:text="足球"
          android:checked="true"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"/>
    <CheckBox
        android:id="@+id/cb_basket"
        android:text="篮球"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <CheckBox
        android:id="@+id/cb_swimming"
        android:text="游泳"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <Button
        android:id="@+id/btn_ok"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    </LinearLayout>

效果:
在这里插入图片描述

七、RadioButton + RadioGroup

<LinearLayout
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TextView
        android:text="性别:"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

    <RadioGroup
        android:id="@+id/rg_gender"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RadioButton
            android:id="@+id/rb_male"
            android:text="男"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

        <RadioButton
            android:id="@+id/rb_female"
            android:text="女"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>

    </RadioGroup>

</LinearLayout>

效果:
在这里插入图片描述

八、ToggleButton

在这里插入图片描述
建立资源文件夹
在这里插入图片描述
初始界面
在这里插入图片描述
编写代码
在这里插入图片描述

<ToggleButton
    android:id="@+id/tb_test"
    android:background="@drawable/selector"
    android:checked="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
</ToggleButton>

效果:
开状态
在这里插入图片描述
关状态
在这里插入图片描述

九、ProgressBar

1.圆形进度条

<ProgressBar
    android:id="@+id/progressbar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
 <TextView
     android:gravity="center"
     android:textSize="20sp"
     android:textStyle="bold"
     android:text="正在加载中..."
     android:layout_width="match_parent"
     android:layout_height="wrap_content"/>

效果:
在这里插入图片描述

2.水平进度条

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <ProgressBar
        android:id="@+id/pb_horizontal"
        android:progress="30"
        android:padding="10dp"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <SeekBar
        android:id="@+id/seekbar"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/tv_progress"
        android:text="当前的进度是:"
        android:textSize="16sp"
        android:gravity="center_horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

</LinearLayout>

效果:

在这里插入图片描述

3.进度条数据绑定

初始化试图和数据绑定

/**
 * 初始化视图
 */
public void initView(){
    // 数据绑定
    pbHorizontal = findViewById(R.id.pb_horizontal);
    seekBar = findViewById(R.id.seekbar);
    tvProgress = findViewById(R.id.tv_progress);
    /* 可拖动进度条的改变事件 */
    seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            // 滑竿改变
            // 设置水平进度条的进度和滑竿的进度一样
            pbHorizontal.setProgress(progress);
            tvProgress.setText("当前进度为:" + progress + "%");  // 设置文本显示的和进度条一致
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            // 拖动进度条完成
            if(pbHorizontal.getProgress() >= pbHorizontal.getMax()){  // 当前进度条的值大于进度条的最大值
                pbHorizontal.setVisibility(View.GONE);  // 进度条消失
            }
            else
            {
                pbHorizontal.setVisibility(View.VISIBLE);  // 进度条可见
            }
        }
    });
}

效果:
拖到100%进度条消失

在这里插入图片描述

今天又起来晚了,摸摸弄弄来到就快九点球了,一上午又过去了。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值