目录
一.Android中drawable或mipmap文件夹存放图片的区别
1.2 Android官方对drawable和mipmap文件夹用途的描述
1.4 Android mipmap中的图标icon 对应的尺寸大小
一.Android中drawable或mipmap文件夹存放图片的区别
1.1 结论
应用图标的图片资源存放在mipmap系列文件夹中,而其余图片存放在drawable系列文件夹中。
1.2 Android官方对drawable和mipmap文件夹用途的描述
drawable文件夹存储bitmap文件(png, jpeg, gif),9-patch文件和xml文件,这些文件用于描述包含多种状态(normal, pressed, focused)的可绘制形状或可绘制对象。
mipmap文件夹用于存放APP的icon图标文件。Android系统会保留这个文件夹中所有的图片资源,而不受到应用安装的设备的屏幕分辨率的影响。这个行为允许启动程序为应用选择最好的分辨率图标显示在主屏幕上。
1.3 Android中mipmap的应用场景
在绝大部分安卓设备的Launcher桌面中,打开或关闭一个APP会有APP打开或关闭的动画效果,例如打开一个APP时会先加载放大该APP的动画,接着便是APP启动界面的放大动画直至填满整个屏幕。
那么在这个放大或缩小APP图标的动画中,使用drawable下的图片作为APP图标,那么整个放大或缩小的动画都只会使用这一张图片,例如一张低分辨率的图片的放大动画效果则会失真,而高分辨率的缩小动画效果会耗费CPU效率来缩放图片;如果使用mipmap下的图片,Android系统则会根据动画对图片的缩放程度,来自动选择最接近当前分辨率的图片来做缩放处理,这样就实现了Google官方文档中描述的更好视觉效果和更高效率的目的。
1.4 Android mipmap中的图标icon 对应的尺寸大小
mipmap-xxxhdpi 对应 192x192px
mipmap-xxhdpi 对应 144x144
mipmap-xhdpi 对应 96x96
mipmap-hdpi 对应 72x72
mipmap-mdpi 对应 48x48
1.5 添加图片
1.5.1直接把需要的图片拖入
1.5.2 右键Open in ->Explorer
二.详解HelloWorld
2.1Activity
2.2布局文件
Ctrl+B转到定义
2.3清单文件
三:布局基础
3.1布局的作用
3.2布局的种类
帧布局:有层次的布局,可覆盖
3.3 添加布局方式
四.线性布局
4.1 线性布局的使用
布局文件的创建只能英文小写,可下划线数学,数字不能开头
match_parent:匹配父容器也就是外层容器,如果没有父容器则匹配的是窗口
wrap_content:大小随着内容的增大而增大
4.1.1 layout_weight作用
<!--layout_weight权重两个作用 --> <!--1.设置某些特殊效果的布局 2.按比例划分空间-->
作用1:长度靠后控制,由于第一个设置了layout_weight,其他的没有设置,其长度后控制,即其他先摆放好,剩余长度为第一个长度。这种情况给layout_weight赋任何值效果一样。
<?xml version="1.0" encoding="utf-8"?>
<!--vertical垂直的,horizontal水平的,默认水平-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!--layout_weight权重 -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="帅,就是帅"
android:background="#ff0000"
android:layout_weight="1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="帅,就是帅"
android:background="#00ff00"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="帅,就是帅"
android:background="#0000ff"/>
</LinearLayout>
效果
作用2:按比例划分区域,layout_width一般设为0dp,避免其他影响。将layout_weight非别设为3,2,1,根据值按比例划分
<?xml version="1.0" encoding="utf-8"?>
<!--vertical垂直的,horizontal水平的,默认水平-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<!--layout_weight权重 -->
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="帅,就是帅"
android:background="#ff0000"
android:textSize="10sp"
android:layout_weight="3"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="帅,就是帅"
android:textSize="10sp"
android:background="#00ff00"
android:layout_weight="2"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="帅,就是帅"
android:textSize="10sp"
android:background="#0000ff"
android:layout_weight="1"/>
</LinearLayout>
效果:
4.1.2 layout_gravity重力:重力摆放
五.综合案例
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:background="#333333"
android:paddingLeft="15dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="《"
android:textColor="#ffffff"
android:textSize="26sp"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="黎旭"
android:textColor="#ffffff"
android:textSize="26sp"
android:layout_gravity="center_vertical"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/menu_logout_icon"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:orientation="horizontal"
android:background="#cccccc">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/chatting_setmode_voice_btn_normal"
android:layout_gravity="center_vertical"/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/sns_shoot_emotion_icon_normal"
android:layout_gravity="center_vertical"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/type_select_btn_nor"
android:layout_gravity="center_vertical"/>
</LinearLayout>
</LinearLayout>