android学习之路(一)
来源:互联网 发布:it培训公司起名 编辑:程序博客网 时间:2024/06/07 06:23
学到知识就记录在这里!
1.android studio中 project相当于Eclipse里Workspace,studio中的module相当于eclipse中的project;
2.http://androidxref.com android系统源码网站
3.www.androiddevtools.cn android镜像网站
4.在Editor标签中选择 General (一般 )在选择Code completion 选项,在Code sensitive completion中选择None,即代码提示不区分大小写。
5.Android build tools是android sdk的Build 工具 建议保持更新。对应着gradle中module下的build.gradle中的buildtoolsVersion属性:
android { compileSdkVersion 23 buildToolsVersion "23.0.1"
6.ducumentation for android sdk : sdk api的文档资源;sources for android sdk :Android的源代码压缩包;
7.android device Monitor(监测仪);
8.这里说了一点如果用户设置了requestWindowFeature(window.featyre_NO_TITLE)来设置全票显示,视图树中的布局就只有Content了,解释了为什么requestWindowFeature这个方法一定要在setContentView之前设置才能生效的原因;当程序在oncreate中调用setContentView后,activityManagerService会 回调onresume方法,此时系统才把整个Decorview添加到phone window中,完成绘制;
9.View的测量:MeasureSpec类:通过他测量view,一个32位的INT值,高2位是测量模式,低30位为测量大小;
模式分以下3中:
1)EXACTLY精准值模式 100dp math_parent
2)AT_MOST最大值模式 wrap_content
3)UNSPECIFIED自定义VIEW使用
如果想要自定义的VIEW支持wrap_content属性,就得重写onMeasure P36;
10. 自定义VIEW:
自定义了一个Textview 初始化画笔颜色时使用了:
paint1.setColor(getResources().getColor(android.R.color.holo_blue_light));getResources();方法:是获取项目中的资源文件可以用来获取你说的string,xml还可以获取图片,音乐,视频等资源文件。
11.一个最简单的自定义组件,class代码如下:
public class mTextView extends TextView{ Paint paint1; Paint paint2; public mTextView(Context context,AttributeSet attributeSet){ super(context,attributeSet); paint1=new Paint(); paint1.setColor(getResources().getColor(android.R.color.holo_blue_light)); paint1.setStyle(Paint.Style.FILL); paint2=new Paint(); paint2.setColor(Color.YELLOW); paint2.setStyle(Paint.Style.FILL); } public mTextView(Context context) { super(context); paint1=new Paint(); paint1.setColor(getResources().getColor(android.R.color.holo_blue_light)); paint1.setStyle(Paint.Style.FILL); paint2=new Paint(); paint2.setColor(Color.YELLOW); paint2.setStyle(Paint.Style.FILL); } @Override protected void onDraw(Canvas canvas) { canvas.drawRect(0,0,getMeasuredWidth(),getMeasuredHeight(),paint1); canvas.drawRect(10,10,getMeasuredWidth()-10,getMeasuredHeight()-10,paint2); canvas.save(); canvas.translate(10,0); //在回调父类方法前,实现自己的逻辑,对textView来说是绘制文本前 super.onDraw(canvas); //在回调父类方法前,实现自己的逻辑,对textView来说是绘制文本后 canvas.restore(); }}注意一定要实现2个构造函数:
mTextView(Context context,AttributeSet attributeSet)
mTextView(Context context) {
否则程序不能正确运行 会出现错误
12.遇到一些问题 关于application类,于是去学习了一下:
在android源码中对他的描述是;
* Base class for those who need to maintain global application state. You can
* provide your own implementation by specifying its name in your
* AndroidManifest.xml's <application> tag, which will cause that class
* to be instantiated for you when the process for your application/package is
* created.
SDK中的描述:Application类是为了那些需要保存全局变量设计的基本类,你可以在AndroidManifest.xml的<application>标签中进行自己的实现,这样的结果是:当你的 application或者包被建立的时候将引起那个类被建立。
理解:就是说application是用来保存全局变量的,并且是在package创建的时候就跟着存在了。所以当我们需要创建全局变量的时候,不需 要再像j2se那样需要创建public权限的static变量,而直接在application中去实现。只需要调用Context的getApplicationContext或者Activity的getApplication方法来获得一个application对象,再做出相应 的处理。
17view类:
View类的XML属性、相关方法及说明
XML属性
相关方法
说明
android:alpha
setAlpha(float)
设置该组件的透明度
android:background
setBackgroundResource(int)
设置该组件的背景颜色
android:clickable
setClickable(boolean)
设置该组件是否可以激发单击事件
android:contentDescription
setContentDescription(CharSequence)
设置该组件的主要描述信息
android:drawingCacheQuality
setDrawingCacheQuality(iint)
设置该组件所使用的绘制缓存的质量
android:fadeScrollbars
setScrollbarFadingEnabled(boolean)
当不使用该组件的滚动条时,是否淡出显示滚动条
android:fadingEdge
setVerticalFadingEdgeEnabled(boolean)
设置滚动该组件时组件边界是否使用淡出效果
android:fadingEdgeLength
getVerticalFadingEdgeLength()
设置淡出边界的长度
android:focusable
setFocusable(boolean)
设置组件是否可以得到焦点
android:focusableInTouchMode
setFocusableInTouchMode(boolean)
设置该组件在触摸模式下是否可以得到焦点
android:id
setId(int)
设置该组件的唯一标识。Java代码中可以通过findViewById来获取它
android:isScrollContainer
setScrollContainer(boolean)
设置该组件是否作为可滚动容器使用
android:keepScreenOn
setKeepScreenOn(boolean)
设置该组件是否会强制手机屏幕一直打开
android:longClickable
setLongClickable(boolean)
设置该组件是否可以响应长单击事件
android:minHeight
setMinimumHeight(int)
设置该组件的最小高度
android:minWidth
setMinimumWidtht(int)
设置该组件的最小宽度
android:nextFocusDown
SetNextFocusDownId(int)
设置焦点在该组件上,且按向下键时获得焦点的组件ID
android:nextFocusLeft
setNextFocusLeftId(int)
设置焦点在该组件上,且按向左键时获得焦点的组件ID
android:nextFocusRight
setNextFocusRightId(int)
设置焦点在该组件上,且按向右键时获得焦点的组件ID
android:nextFocusUp
setNextFocusUpId(int)
设置焦点在该组件上,且按向上键时获得焦点的组件ID
android:onClick
为该组件的单击事件绑定监听器
android:padding
setPadding(int,int,int,int)
在组件的四边设置填充区域
android:paddingLeft
setPadding(int,int,int,int)
在组件的左边设置填充区域
android:paddingTop
setPadding(int,int,int,int)
在组件的上边设置填充区域
android:paddingRight
setPadding(int,int,int,int)
在组件的右边设置填充区域
android:paddingBottom
setPadding(int,int,int,int)
在组件的下边设置填充区域
android:rotation
setRotation(float)
设置该组件旋转的角度
android:rotationX
setRotationX(float)
设置该组件绕X轴旋转的角度
android:rotationY
setRotationY(float)
设置该组件绕Y轴旋转的角度
android:saveEnabled
setSaveEnabled(boolean)
如果设置为false,那当该组件被冻结时不会保存它的状态
android:scaleX
setScaleX(float)
设置该组件在水平方向的缩放比
android:scaleY
setScaleY(float)
设置该组件在垂直方向的缩放比
android:scrollX
该组件初始化后的水平滚动偏移
android:scrollY
该组件初始化后的垂直滚动偏移
android:scrollbarAlwaysDrawHorizontalTrack
设置该组件是否总是显示水平滚动条的轨迹
android:scrollbarAlwaysDrawVerticalTrack
设置该组件是否总是显示垂直滚动条的轨迹
android:scrollbarDefaultDelayBeforeFade
setScrollbarDefaultDelayBeforeFade(int)
设置滚动条在淡出隐藏之前延迟多少毫秒
android:scrollbarFadeDuration
setScrollbarFadeDuration(int)
设置滚动条淡出隐藏过程需要多少秒
android:scrollbarSize
setScrollbarSize(int)
设置垂直滚动条的宽度和水平滚动条的高度
android:scrollbarStyle
setScrollbarStyle(int)
设置滚动条的风格和位置。该属性支持如下属性:
insideOverlay
insideInset
OutsideOverlay
OutsideInset
android:scrollbarThumbHorizontal
设置该组件的水平滚动条的滑块对应的Drawable对象
android:scrollbarThumbVertical
设置该组件的垂直滚动条的滑块对应的Drawable对象
android:scrollbarTrackHorizontal
设置该组件的水平滚动条的轨道对应的Drawable对象
android:scrollbarTrackVertical
设置该组件的垂直滚动条的轨道对应的Drawable对象
android:scrollbars
定义该组件滚动时显示几个滚动条,该属性支持如下属性值。
none:不显示滚动条
horizont:显示水平滚动条
vertical:显示垂直滚动条
android:soundEffectsEnabled
setSoundEffectsEnabled(boolean)
设置该组件被单击时是否使用音效
android:tag
为该组件设置一个字符串类型的tag值。接下来可通过View的getTag()获取该字符串,或通过findViewWithTag()查找该组件
android:transformPivotX
setPivotX(float)
设置该组件旋转时旋转中心的X坐标
android:transformPivotY
setPivotY(float)
设置该组件旋转时旋转中心的Y坐标
android:translationX
setTranslationX(float)
设置该组件在X方向上位移
android:translationY
setTranslationY(float)
设置该组件在Y方向上位移
android:
setVisibility(int)
设置该组件是否可见
- Android学习之路(一)
- android学习之路(一)
- Android学习之路(一)
- Android学习之路一
- 学习Android之路一
- android学习之路(一)--Glide学习
- Android学习之路之数据的使用(一)
- Android学习之surface学习(一)
- Android开发之路(一)---如何开始学习Android
- android 学习之---Android之SurfaceView学习(一)
- Android 学习之路(一) —— WebSiteDoor
- Android学习之路(一)——万事开头难
- android学习之路(一) 环境搭建
- Android学习之路(一) 环境搭建
- Android学习之路--View--绘制过程(一)
- Android vr开发学习之路(一)
- Android学习二之Activity(一)
- android之学习杂记(一)
- win7下IIS的安装和配置 图文教程
- C++ 11 正则表达式
- UVA(11054)
- PHP中全局变量global和$GLOBALS[]的区别
- OutOfMemoryError --- Java heap space
- android学习之路(一)
- 《Java编程思想第四版》笔记---14章 类型信息
- 月入十万:大部分人努力的方向都错了
- Eclipse的简易教程
- AS插件之Gsonformat——自动帮你生成GSON BEAN
- Codeforces Round #326 (Div. 2) D. Duff in Beach
- wampserver 为橙色 可以打开localhost 不能打开phpmyadmin
- HDU1542&&POJ1151-Atlantis
- C语言传值与传值笔记