码迷,mamicode.com
首页 > 移动开发 > 详细

安卓第一次小结

时间:2015-05-24 06:40:31      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:文本框

文本框:

   存放文本的


   <TextView

        android:id="@+id/textView1"

        //控件的身份

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

                                                  //wrap_content 适应内容

                                                 // match_parent 填充容器

                                                //fill_parent  跟match_parent 一样的

                                               //直接使用整数    单位 dp

        android:layout_alignLeft="@+id/textView2"

        android:layout_below="@+id/textView2"

        android:layout_marginTop="78dp"

        android:text="TextView"

                                        //显示文本的内容

         android:textColor="#ffff0000"

                                 //颜色属性: 值:  #开头  透明度  红 绿  蓝

                                              不设置透明度默认就是ff

         android:textSize="13sp" 

                             //字体的大小   单位 sp

          android:textStyle="bold" 

                            //字体样式  只有三种

           android:background="#00ff00"

                           //背景颜色

 />




code:

  查找控件:

    TextView textView = (TextView) findViewById(R.id.textView1);

Button   按钮

     TextView的子类

<EditText

        android:id="@+id/editText1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_alignParentRight="true"

        android:layout_below="@+id/button1"

        android:layout_marginTop="21dp"

        android:ems="10" 

                       //默认长度  单位字符

       android:hint="请输入密码"  

      android:inputType="textPassword"

                      //输入文本的格式

>

        //查找控件

        Button button = (Button) findViewById(R.id.button1);

        mEditText = (EditText) findViewById(R.id.editText1);

        mTextView = (TextView) findViewById(R.id.textView1);

       

        //事件监听 //点击事件

        button.setOnClickListener(new OnClickListener() {

   

   @Override

   public void onClick(View v) {

    String string = mEditText.getText().toString();

    mTextView.setText(string);

   }

  });

问题解决:

1、FC

      出现错误,是否强制关闭

2、日志 LogCat

       verbose   所有信息   Log.v(String str,String str);   //黑色

       debug    调试的信息     //蓝色

       info

       warn

       erro           红色

      

assert 断言

  

3、解决FC

      1、看日志

      2、看出错的原因

     技术分享

     3、找出错的代码

        从上往下找第一出现自己写的代码的位置

        一般情况下是在Caused by 下面第一句技术分享

      4、双击定位过去

 4、工程出错

     重新编译

5、R出错

       1、资源问题 (资源命名问题   a~z _ 数字   数字不能开头)

       2、R文件导入错误(可以导入了 android.R)

       3、编译(忘了自动编译)

             a、Project ---> Build Auto……   要勾上

             b、重新编译

                   Project ---> Clean

6、拖动控件出现  ClassCastException

            Project ---> Clean



Genymotion的使用:(极速模拟器)

       Genymotion + VirtualBox

使用步骤:

   1、安装

   2、安装完成之后打开Genymotion,打开完成之后关闭

   3、把镜像文件copy到

     C:\Users\admintor\AppData\Local\Genymobile

     覆盖掉

   4、

ImageView   存放图片

    <ImageView

        android:id="@+id/imageView1"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:src="@drawable/ic_launcher"

                                         //前景图片

        android:scaleType="center" 

                                   //center  居中

                                  //fitxy   拉伸适应控件大小

                                  //fitStar   从左上角为原点拉伸(图片比例不会改变)

       />

code:

     //设置前景图片

        imageView.setImageResource(R.drawable.ic_launcher);

        //设置背景

        imageView.setBackgroundResource(R.drawable.ic_launcher);

       //设置拉伸模式

        imageView.setScaleType(ScaleType.FIT_XY);

ImageButton  

          ImageView的子类

布局管理器:

    

1、LinearLayout  线性布局

<LinearLayout  
    android:orientation="horizontal"

                    //方向   值:  horizontal 水平方向

                                           vertical   垂直方向

 >

    特殊属性:

         只有当控件放在LinearLayout中这个属性才生效

          android:layout_weight="2"   

                                         //权重    分割剩余空间

           android:layout_gravity="center"

                                               值: 上下左右 居中(水平居中、垂直居中)

    通用属性:

           控件在任何布局中都有的属性

                 //设置控件跟内容之间的间隙

                   android:padding="20dp"  //上下左右

                    android:paddingLeft="10dp"         左

                   android:paddingRight="20dp"       右

                     android:paddingTop="30dp"        上

                   android:paddingBottom="40dp"    下

          控件之间的间隙

          android:layout_margin="20dp"   //上下左右

          android:layout_marginLeft="10dp"

        android:layout_marginRight="20dp"

        android:layout_marginTop="30dp"

        android:layout_marginBottom="40dp"


          内容在控件中的对齐方式

         android:gravity="top|right"


RelativeLayout 相对布局


       控件在布局中的对齐方式

          android:layout_alignParentLeft="true"  左对齐

        android:layout_alignParentTop="true"   上对齐

       android:layout_alignParentRight="true" 右

        android:layout_alignParentBottom="true"  下

        android:layout_centerHorizontal="true"   水平居中

       android:layout_centerVertical="true"     垂直居中

       android:layout_centerInParent="true" 居中


     控件之间的对齐方式

      android:layout_alignTop="@+id/textView2"  上

      android:layout_alignLeft="@+id/textView2"  左

      android:layout_alignRight="@+id/textView2"  右对齐

      android:layout_alignBottom="@+id/textView2" 下对齐


     控件之间的位置关系:

      android:layout_above="@+id/tf"  在xx之上

      android:layout_toLeftOf="@+id/tf"  在 左边

        android:layout_toRightOf="@+id/tf"   右边

        android:layout_below="@+id/tf"  在xx之下


FrameLayout 帧布局

   特性:层叠控件

           android:layout_gravity="right"  


TableLayout   表格布局

     每一行都是 tablerow

           高度是由每一行中高度最高的那个控件决定

           宽度是由每一列中宽度最宽的那个控件决定


AbsoluteLayout  绝对布局  (不建议使用)




GridLayout   网格布局 (4.0之后新增)

     android:layout_column="2"

        android:layout_row="3"      //声明控件所在的行列


    android:layout_columnSpan="2"

        android:layout_rowSpan="2"  //声明控件所占用的行列



布局是可以进行嵌套的。



安卓第一次小结

标签:文本框

原文地址:http://10114413.blog.51cto.com/10104413/1654523

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!