android:text=”” //设置文本内容 既然有设置文本内容了,那么就有对于文本的一些颜色,大小,字体的设置 android:singleline=“true”文字单行排列,显示不了的字会默认变成…在后面 android:ellipsize 用来设置单行排列下显示不了的文字…出现的位置或者怎么处理 有5个选项 none 没有 start …出现在开头 middle …出现在中间 end …出现在末尾 marquee 循环,跑马灯样式出现
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:text="文本" android:singleLine="true" android:ellipsize="marquee" android:focusable="true" android:focusableInTouchMode="true" android:textSize="20sp" android:textColor="@color/white" /> 跑不起来是我添加的文字还不够多android:focusable=”true” android:focusableInTouchMode=”true” 上面这两个属性是获取焦点的意思
还有四个调整位置的属性是在textview这一脉下用的比较多的 android:paddingLeft="20dp" android:paddingRight="20dp" android:paddingTop="20dp" android:paddingBottom="20dp" 用来设置文本信息和控件的内边距用的比较多,在其他的控件里面比较少见到,比较常见的特性好像就这么几个,至于怎么使用我想还是比较简单,这里就不说了,其实就是和把一些文字准备好,然后用双面胶,透明胶之类的往一个布局里贴是一样的。 下面就介绍他的两个儿子Button和EditText 先说听话点的EditText,从字面上很好理解就是编辑文本就是指文本框,既然是儿子,所以继承了他爹所有的特性,当然也会有他自己的个性,这里就说我经常见到的。 EditText最常见的用途是用在输入账号密码之类的功能 <LinearLayout android:layout_width="match_parent" android:layout_height="48dp" android:layout_weight="1" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="match_parent" android:text="@string/login_zhanghao" android:gravity="center_vertical" android:textSize="12sp" android:paddingLeft="10dp" /> <EditText android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="match_parent" android:id="@+id/login_et_zhanghao" android:gravity="center_vertical" android:paddingLeft="10dp" android:hint="@string/login_inputzh" /> </LinearLayout> <TextView android:layout_width="match_parent" android:layout_height="10dp" /> <LinearLayout android:layout_width="match_parent" android:layout_height="48dp" android:layout_weight="1" android:orientation="horizontal" > <TextView android:layout_width="60dp" android:layout_height="match_parent" android:text="@string/login_password" android:gravity="center_vertical" android:textSize="12sp" android:paddingLeft="10dp" /> <EditText android:layout_width="wrap_content" android:layout_weight="1" android:layout_height="match_parent" android:id="@+id/login_et_password" android:inputType="textPassword" android:gravity="center_vertical" android:paddingLeft="10dp" android:hint="@string/login_inputpsw" /> </LinearLayout>android:inputType=”textPassword”
密码的黑圆圈就是上面这句属性所带来的效果 对于EditText这就是他的个性,还有就是他会抢焦点,光标会出现在输入框里面然后输入法会弹起来,有些人不喜欢这样,也行那就用上文提到的设置焦点的方法,让他所在的布局先获得焦点那就可以了解决这个问题了。 至于Button,字面上意义上说就是按钮,很容易理解,按一下有惊喜或者是惊讶(bug)抑或是啥都没有,,特性上完全继承它爸,而且有点叛逆,抢焦点以至于其他控件点击没反应,从出生到现在就是关注的对象,所以有些时候发现控件点击没反应是不是这界面当中包含了button把焦点抢去了,解决方法还是一开始提到那个设置焦点的方法 再补充一下一个控件基本的一些属性 android:layout_width="60dp" android:layout_height="match_parent" 这是每个控件必有的属性,除了给数值给他还有三个选项match_parent 占满 fill_parent 占满 wrap_parent 根据控件自身的默认的大小来决定
有人说有两个占满会不会重复了,我百度了一下,据说是因为版本的原因在很久之前都是用fill_parent,match_parent是最近才兴起的。android:id跟身份证一样,一个控件就算是同类也只能有一个id android:background=”@color/app_bg” 设置背景
至于其他的一些因为布局带来的特有属性就在介绍布局的时候再总结吧,今天上午写代码状态不好,用写博客来调整下,主要是昨晚没睡好,现在还是眼皮重重的,总之这段时间进步是自己看得到的,继续加油,做更好的自己。