Android学习笔记三常用控件

             接着讲解Android的开发,本篇主要讲解基本控件的使用和介绍,基本控件:EditText       TextView       Button           ImageButton            RadioButton    

CheckBox       ImageView    

               文本框和编辑框的区别:EditText是TextView的子类,TextView文本框不可编辑而EditText是可编辑的

            TextView的常用属性:android:autoLink:是否将符合指定格式的文本转换为可单击的超链接形式:取值  none|web|email|phone|map|all

                                            android:text  设置文本框内文本内容

                                             android:singleLine 当为true的时候,文本框不会换行

                                             android:password   密码框

                                            android:phoneNumber 电话号码框

                                            android:line   设置默认占几行        android:lines   设置最少占几行

                                            android:textColor    字体颜色是什么

                                            android:textColorHighlight  设置被选中时的颜色是什么

                                            android:textsize  字体大小,  android:textStyle  字体风格  :如粗体和斜体                 typeface:字体

                                            android:ellipsize文本超过TextView的长度是如何处理   none|start|middle |end |marquee

      Button 与ImageButton区别

                 android:text属性,在按钮上显示文字,ImageButton不能有文字

                 android:background 可以给按钮指定背景图片或颜色

                 android:src给ImageButton设置Drawable资源文件

                 android:adjustViewBounds="true" 调整边框以适应图片大小

           如何给Button添加鼠标点击事件如下:

                       Button sharmeBtn=(Button)findViewById(R.id.sharmeBtn);

                        sharmeBtn.setOnClickListener(new OnClickListener(){

                                  public void onClick(View v){

                                            Log.i("sharme",“welcome here! dear my Button Click”);

                                  }

                 });

 

下面来说说Drawable.xml资源文件

         如果我们在使用Button的时候,特别是点击的时候,想做出的按下和抬起的这两个动作,用不同的图片或文字来显示状态,这时候我们可以这样做:

<?xml version="1.0" encoding="utf-8">

          <selector xmlns:android=http://schemas.android.com/apk/res/android>

                     <item android:state_pressed="true"

                                android:drawable="@drawable/btn_down"

                      />

                       <!--注意上面是按下的图片,而下面是正常的图片-->

                      <item android:drawable="@drawable/btn_up"/>

         </selector>

<--ImageButton只能显示图片而不能显示文字,解决这个问题:设置Button的background属性可以有图片也可以有文字-->

       <Button

                android:id="@+id/loginBtn"

                 android:layout_below="@+id/loginOneBtn"

                android:layout_width="wrap_content"

                adnroid:layout_height="wrap_content"

                android:background="@drawable/btnOk"

                android:text="have word"

      />

      对于RadioButton和CheckBox       

android:checked属性,RadioGroup是用于将单选组合框,归纳取来,或者包括起来的component

如图应用:

      

</xml>

 

ImageView的用法

          继承自View,可用来显示图片,android:src  这个属性设置ImageView所显示的Drawable资源的ID

           android:maxHeight 最大高度             android:maxWidth 最大宽度

            android:adjustViewBounds设置ImageView是否调整自己的大小保持所显示图片的长度比

           android:scaleType 设置图片如何缩放以适应ImageView的大小,取值如:matrix使用matrix方式缩放     fitXY:对图片横向向纵向独立缩放,使得图片完全填充ImageView,可能会变形

          fitStart:保持缩放比,图片较长的边与ImageView对应边一致,然后放在左上角

          fitColor保持缩放比,图片较长的边与ImageView对应边一致,然后放在中间

          fitEnd 保持图片缩放比,图片较长的边与ImageView的对应边一致,然后放在右下角

           center图片放在中间,不缩放     centerCrop保持横比缩放,使得图片能完全覆盖ImageView    centerInside保持纵横比缩放,使得ImageView能完全显示图片

 

如下是对应ImageView的一个实例:

          

 下次将贴出程序的制作代码,会比上面图片功能更加全面

    

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值