###1.View
Android所有控件全都继承自View类,(需要在.java文件中导入android.view.View;)具有所有的View属性。
####1.1TextView:用来显示文本信息
ex:
<TextView
android:id="@+id/textView1"//表示该控件的id,在布局文件中或者代码中被引用
android:layout_width="match_parent"//填满父控件
android:layout_height="wrap_content"//裹住内容,不设置具体值
android:text="@string/easy_text"
android:gravity="center_vertical"//设置文本纵向居中
android:paddingLeft="5dip"//设置内边距
android:layout_marginTop="5dip"//设置外边距
android:textColor="@color/colorPrimaryDark"/>
#####wrap_content&wrap_content&fill_parent的区别:
- wrap是根据容器内的东西决定组件的大小,比如一个按钮,按钮中的字体大,那么这个按钮就大,字体小那么相应的按钮就会小些。
- match的话是指“填充满”父容器。但是他跟fill_parent是不一样的,fill是真的填满,没有条件。而match的话有自动调整的功能
#####android:text=”@string/easy_text”—— android:textColor=”@color/colorPrimaryDark” - 表示显示的文本信息是strings.xml中name=easy_text的内容,文本颜色是colors.xml中name=colorPrimaryDark的颜色
- 另一种写法是android:text=”你们好”;android:textColor=”#303F9F”(不推荐)
####1.2 EditView:用来编辑输入的文本信息
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="密码"//表示在输入之前的提示
android:SingleLine="ture"//文本输入框不可换行输入,只能在一行内输入文本
android:inputType="textPassword"
/>
#####android:inputType=”textPassword”
- 表示输入框是用来输入密码的,输入的文本会自动变为“.”,起到隐藏用户密码的作用。
- 另一种写法是android:password=”true”
####1.3Button:按钮组件
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="ButtonClick"
android:text="登录" />
#####android:onClick=”ButtonClick”
- 该属性在源代码中设置一个ButtonClick方法,作为该Button的点击监听方法
- 实现监听还可以调用findViewById(int id)找到该Button,后续文章会应用的
1.4ImageView:展示图片
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="5"
android:scaleType="center"//表示图片以何种形式填充到View对应的矩形区域
android:src="@drawable/cat" />//设置填充的图片