基本的UI组件

 

1TextViewEditText(文本控件)

 

      1.1

          android:layout_width  (wrap_content/fill_parent)

          android:width  (dp)

          android:ems    指定占几个汉字

          android:singleLine   true/false

          android:maxWidth

          android:minWidth

          android:minEms

          android:maxEms

          android:maxLength  真正的长度

 

      1.2

          android:layout_height  (wrap_content/fill_parent)

          android:height  (dp)

          android:lines    指定占几行

          android:singleLine   true/false

          android:maxHeight

          android:minHeight

          android:minLine

          android:maxLine

 

      1.3 文本格式

          android:textColor

          android:textSize  sp)  

          android:typeface  字体

          android:gravity  对齐方式      

 

      1.4 走马灯效果(android:singleLine="true"设置)

          android:ellipsize

          android:marqueeRepeatLimit

 

      1.5 EditText特有的属性

           子标签,主动要求获得焦点

          android:inputType  限定输入内容的类型,这里可以设定所有能限定的类型

          android:hint  无内容时自动提示的文字

          android:textColorHint  无内容时自动提示的文字的颜色

          android:numeric  限定输入内容的只能是某种数字(范畴比inputType小)

 

 2、各种Button

 

       2.1 ToggleButton

           android:textOn=""

           android:textOff=""

 

           ToggleButton设置一个监听器OnCheckedChangeListener(是android.widget.CompoundButton.OnCheckedChangeListener

           监听器中的方法public void onCheckedChanged(CompoundButton buttonView,boolean isChecked)

           isChecked参数表示开关按钮当前的状态是打开还是关闭

 

           实例:通过开关改变背景色

           

           // 只能通过获得当前Activity对象的window对象来重画背景色,代码如下

           MainActivity.this.getWindow().setBackgroundDrawable(drawable);

 

           // 其中绘画对象drawable如何创建

           // 从资源(如:res\drawable文件夹下的一个图片)创建

           // 如果只是改颜色,就使用颜色配置文件即可(如:res\values\color.xml

           // color.xml是资源文件,自己建

           Drawable drawable = getResources().getDrawable(R.color.white);

 

      2.2 RadioButton/RadioGroup

 

          RadioGroup设置一个监听器OnCheckedChangeListener(是android.widget.RadioGroup.OnCheckedChangeListener

          监听器中的方法public void onCheckedChanged(RadioGroup group,int radioId)

          radioId参数表示是哪一个单选按钮被选中

 

          RadioButton rBtn = (RadioButton) group.findViewById(checkedId); //【注意】findViewByIdgroup下的方法

  String txt = rBtn.getText().toString();

          txtview.setText(txt);//【注意】实际项目中,显示出来看的字符,不等于它的值

                               // 比如:显示出来的是“男”“女”,实际服务器端需要它们对应的值01

 

      2.3 CheckBox

          同上的思路

 

 3ImageView实例

 

     3.1 准备好三张图片放在res\drawable-mdpi

 

     3.2 布局好实例的显示界面

 

         3.2.1 为了这个例子看效果,有边框更方便,如何显示边框

            1】自己在res\layout\border-bg.xml

            2】需要显示边框的控件设置属性  

           android:backgroud="@layout/border-bg"                                                      android:layout_margin="5dp"

 

         3.2.2 设置ImageView固定宽高,而且不被撑开,必须设置7个属性

                     layout_widthlayout_height只能是wrap_content

                     widthheight必须固定

                     maxWidthmaxHeight必须固定

                     adjustViewBounds="true"

 

         3.2.3 指定显示某张图片android:src="@drawable/img1"

 

         3.2.4 指定图片显示的方式android:scaleType="centerInside"  centerInside表示等比缩放居中

 

         3.2.5 【下一张】按钮的处理,更改src属性指向的图片

               Bitmap  bitmap = BitmapFactory.decodeStream(?);

                      ? --> getResources().openRawResource(R.drawable.img1);

 

               imageView.setImageBitmap(bitmap);

 

         3.2.6 【设置透明度】imageView.setAlpha(int alpha);

                      alpha0~2550表示完全透明,255表示完全实心

 

 

4SeekBar实例

 

    4.1  两个重要的属性

                 android:max   逻辑最大值

                 android:progress    当前刻度

 

    4.2  一个重要的事件OnSeekBarChange

 

    4.3  按钮配合SeekBar,模拟一下歌曲的播放

 

        4.3.1 SeekBar的两个属性设置一下

 

        4.3.2 播放按钮的单击事件:启动一个线程,不断地增加SeekBarprogress,直到progress达到max

 

        4.3.3 停止按钮的单击事件:想让线程停止,解决办法是在线程类中设置一个标志位,这个标志位影响run方法中的while循环条件

 

             要将SeekBarprogress复位

 

       4.3.4 暂停按钮的单击事件:也是让线程停止

 

             播放,暂停,停止,这三个操作都要考虑三部分的事情:

                1)  看线程要不要启动或停止

                2)  看标志位怎么改

                3)  看SeekBarprogress要不要改

更多相关文章

  1. 安卓开发小效果--走马灯
  2. Android部分控件的特殊属性
  3. Android(安卓)API中文文档GridView
  4. Android利用TextView制作跑马灯该效果
  5. Android(安卓)API中文文档GridView
  6. 【Android】自带Theme
  7. Android(安卓)layout布局属性、标签属性总结大全。
  8. 【转】android中Textview如何限制在一行显示且多余字符自动截断
  9. Android设置去掉 外部USB存储和默认存储选项

随机推荐

  1. Android之EditText imeOptions属性解析
  2. Android性能调优工具TraceView介绍
  3. 用.Net打造一个移动客户端(Android/IOS)的
  4. 基本组件之列表选择框
  5. Android系统
  6. Android(安卓)Activity之间跳转出现短暂
  7. Android(安卓)4.0已知信息汇总
  8. 移动应用平台首选iOS还是Android?
  9. adb shell 命令详解
  10. Android(安卓)Studio自带的sdk manager打