--------------------- 控件 --------------------- ---------------------
1.TextView 控件常用属性:
android:id–控件的id //"@+id/textView1"
android:layout_width–控件宽度
android:layout_height–控件高度
//warp_content:包裹实际文本内容,文本有多宽,它就有多宽
//match_parent:当前控件铺面父类容器(2.3API之后添加的属性值)
//fill_parent:当前控件铺满父类容器 (2.3API之前添加的属性值)
android:text–文本内容
android:textSize–文本大小 //"28sp"
android:textColor–文本颜色 //"#000000"
android:background–控件背景
---------------------
2.EditView控件 除拥有TextView的常用属性外还有以下属性:
android:hint–输入提示文本 //"请输入你的姓名"
android:inputType:输入文本类型(例如:纯数字)
//android:inputType="textPassword" //设置输入格式为密码格
//android:inputType="phone" //设置输入格式为拨号键盘
---------------------
3.ImageView 控件用于显示图片 ,常用属性:
android:src="@drawable/ic_launcher" //ImageView的内容图像
android:background:"@drawable/ic_launcher" //ImageView背景图片
android:background="#00ff00" //设置ImageView的颜色
也就是说一般将APP的icon放在minmap文件夹下,其他图片资源放在drawable文件夹下。
图片资源放到drawable-v24里面,导致7.0以下不能找到图片 不同的drawable文件夹用于为设备兼容性和不同的Android版本提供不同的屏幕密度。同理mipmap-anydpi-v26 API 26(安卓8.0)也是一样的道理,注意不同的文件对应的不同的版本。
---------------------
Button有text属性,ImageButton没有。
ImageButton有src属性,Button没有。
.xml文件访问Strings.xml中的资源:
<Button
android:text="@string/button_name"/>
/>
tools:context 作用
tools:context="activity name"这一句不会被打包进APK。只是ADT的Layout Editor在你当前的Layout文件里面设置对应的渲染上下文;
拿一个简单 tools:text 举个例子更形象些,方便进一步理解 tools:context
TextView 采用了 android :text , 而 EditText中使用了 tools:text ,右边Layout 编辑器会显示内容Name , sample name 两个 字体, 如果你运行代码后编译,生成apk 后,终端就只显示Name,不会显示Sample Name这个字样. 大家可以试试运行,看下效果就知道。
--------------------- 布局 --------------------- ---------------------
1.LinearLayout 线性布局
android:
android:orientation="vertical" //垂直
android:orientation="horizontal" //水平
2.ConstraintLayout 约束布局
app:
layout_constraintLeft_toLeftOf view1左边对齐view2的左边
layout_constraintLeft_toRightOf view1左边对齐view2的右边
layout_constraintRight_toLeftOf view1右边对齐view2的左边
layout_constraintRight_toRightOf view1右边对齐view2的右边
layout_constraintTop_toTopOf view1顶部对齐view2的顶部
layout_constraintTop_toBottomOf view1顶部对齐view2的底部
layout_constraintBottom_toTopOf view1底部对齐view2的顶部
layout_constraintBottom_toBottomOf view1底部对齐view2的底部
layout_constraintBaseline_toBaselineOf view1基准线对齐view2的基准线
layout_constraintStart_toEndOf view1起始位置对齐view2的结束位置
layout_constraintStart_toStartOf view1起始位置view2的起始位置
layout_constraintEnd_toStartOf view1结束位置对齐view2的起始位置
layout_constraintEnd_toEndOf view1结束位置对齐view2的结束位置