Android知识
四大组件是什么?
Activity【活动】:用于表现功能。
Service【服务】:后台运行服务,不提供界面呈现。
BroadcastReceiver【广播接收器】:用来接收广播。
Content Provider【内容提供商】:支持在多个应用中存储和读取数据,相当于数据库。
四个组件的生命周期?
Activity生命周期图及 Fragment生命周期图
Service的生命周期:首先Service有两种启动方式,而在这两种启动方式下,它的生命周期不同。
通过startService()方法启动的服务
初始化结束后系统会调用 void onStart(Intent intent) 方法,用于处理传递给startService()的Intent对象。如音乐服务会打开Intent 来探明将要播放哪首音乐,并开始播放。注意:多次调用startService()方法会多次触发onStart()方法。
通过bindService ()方法启动的服务
初始化结束后系统会调用 IBinder onBind(Intent intent) 方法,用来绑定传递给bindService 的Intent 的对象。注意:多次调用bindService()时,如果该服务已启动则不会再触发此方法。
Service生命周期
广播:
fragment各种情况下的生命周期
都用了那些框架
dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'com.android.support:appcompat-v7:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
/*公司DFMSG*/
implementation files('libs/DFMsg1.0.1.1.jar')
implementation files('libs/gson-1.7.2.jar')
/*图片加载框架*/
implementation files('libs/glide-3.6.0.jar')
/*网络框架*/
implementation 'com.lzy.net:okgo:3.0.4'
/*列表*/
implementation 'com.android.support:recyclerview-v7:26.1.0'
/*大厅SDK*/
implementation files('libs/LoginSDKUtils.jar')
/*首页轮播图*/
implementation 'com.youth.banner:banner:1.4.10'
/*新闻左右切换列表*/
implementation 'com.flyco.tablayout:FlycoTabLayout_Lib:2.1.2@aar'
/*上拉下刷*/
implementation 'com.github.open-android:PullToRefresh:v1.0'
/*设置字体*/
implementation 'uk.co.chrisjenx:calligraphy:2.2.0'
/*图片缩放*/
implementation 'com.github.chrisbanes:PhotoView:2.0.0'
/*树状列表*/
implementation 'com.github.bmelnychuk:atv:1.2.+'
}
布局都有哪些
一、FrameLayout(帧布局):
显示特点:所有的子控件默认显示在FrameLayout的左上角,会重叠在一起显示。
常用属性:
layout_gravity(设置给子控件,调整控件在容器内的重心)
常用值:
left(左)、 right(右)、
top(上)、 bottom(下)、
center(中心)、 center_vertical(竖向中心)
center_horizontal(横向中心)
二、LinearLayout(线性布局):
显示特点:所有子控件按照横向或者竖向依次排列,android:orientation=“vertical”(竖向),android:orientation=“horizontal”(横向)。
常用属性:
①gravity(控件本身内的重心位置)
常用值:
left(左)、right(右)、top(上)、bottom(下)、center(中心)、
enter_vertical(竖向中心)、center_horizontal(横向中心)
注意的是属性还可以这样使用android:gravity="bottom|center"表示底
部中心
②layout_gravity(控件在父容器内的重心位置)
常用值:
left(左)、right(右)、top(上)、bottom(下)、center(中心)、
enter_vertical(竖向中心)、center_horizontal(横向中心)
③layout_weight(权重值)
子控件的用法:android:layout_weight=“1” 多个控件同时使用,可以实现平分的效果
④weightSum(权重总和)
三、RelativeLayout(相对布局)
显示特点:和LinearLayout布局相似,所有子控件默认显示在RelativeLayout的左上角
常用属性:
①在指定控件的哪一边:(注意:这些属性都需要有一个指定的id)
layout_toRightOf 在指定控件的右边
layout_toLeftOf 在指定控件的左边
layout_above 在指定控件的上边
layout_below 在指定控件的下边子控件对齐关系
常见的效果:
②指定和那个控件的对齐方式(注意:这些属性都需要有一个指定的id)
layout_alignRight 与指定控件右对齐
layout_alignLeft 与指定控件左对齐
layout_alignTop 与指定控件上对齐
常见的效果:
③子控件与父容器间对齐关系(这些属性的值为true或false)
layout_centerInParent 与父容器中间对齐 pairunte
layout_centerVertical 与父容器竖向中心对齐
layout_centerHorizontal 与父容器横向中心对齐
layout_alignParentLeft 与父容器左边对齐
layout_alignParentTop 与父容器上边对齐
layout_alignParentRight 与父容器右边对齐
layout_alignParentBottom 与父容器下边对齐
四、GridLayout(网格布局)
显示特点:所有子控件默认在GridLayout中横向依次排列,当只等每行的列数时,到达指定列数
会自动换行显示。
常用属性:
layout_column 在网格的第几列
layout_row 在网格的第几行
layout_columnSpan 跨列
layout_rowSpan 跨行
layout_gravity 在一个网格中的重心位置
columnCount 每行列总数
常见的效果:
五、TableLayout(表格布局)
表格布局和网格布局类似,但是需要注意的是,表格布局不能跨行,只能跨列