Android 学习 - Vo7ice/Vo7ice.github.io GitHub Wiki
- 记录遇到的问题所需要的知识
-
View
提供的获取坐标方法 -getTop()
: 获取到的是View
自身的顶边到其父布局顶边的距离 -getLeft()
: 获取到的是View
自身的左边到其父布局左边的距离 -getRight()
: 获取到的是View
自身的右边到其父布局左边的距离 -getBottom()
: 获取到的是View
自身的底边到其父布局顶边的距离 -
MotionEvent
提供的方法 -getX()
: 获取点击事件距离控件左边的距离,即视图坐标 -getY()
: 获取点击事件距离控件顶边的距离,即视图坐标 -getRawX()
: 获取点击事件距离整个屏幕顶边的距离,即绝对坐标 -getRawY()
: 获取点击事件距离整个屏幕左边的距离,即绝对坐标
-
修改默认加密手机:修改fstab.in中的flag
FLAG_FDE_TYPE/或修改device\mediatek\ [project]\ fstab.{ro.hardware} forceencrypt->encrypt -
自定义控件属性时:
TypedArray ta = context.obtainStyledAttributes(attrs,R.styleable.TopBar);
obtainStyledAttributes
需要调用两个参数的函数,不然自定义属性不起作用 -
在
onDraw
方法中调用画布canvas
的translate
方法将绘制的位置进行平移(+width为左,+height为下) -
在
LinearGradient
渐变器中public LinearGradient( float x0,//渐变器x起始线 float y0,//渐变器y起始线 float x1,//渐变器x终止线 x1-x0为渐变器宽度 float y1,//渐变器y终止线 y1-y0为渐变器高度 int color0,//靠近起始线颜色 int color1,//靠近终止线颜色 TileMode tile)//平铺形式 有CLAMP,REPEAT,MIRROR
-
为控件添加触摸水波纹效果,在
style
中配置了material
主题后在xml
布局文件中增加属性-
android:background="?android:attr/selectableItemBackground"
-
android:background="?android:attr/selectableItemBackgroundBorderless"
-
<item name="android:colorControlHighlight">@color/colorAccent</item>
可以更改波纹的颜色 -
为自定义背景添加水波纹效果
<ripple xmlns:android="http://schemas.android.com/apk/res/android" android:color="@android:color/white"><!-- 水波纹颜色 必须--> <item> <!-- 原block--> </item> </ripple>
-
-
给英文设置粗体的方法:
- 在
xml
中android:textStyle="bold"
- 在代码中,
tv.getPaint().setFakeBoldText(true);
- 在
-
hasOverLapping
自定义View
时重写hasOverlappingRendering
方法指定View
是否有Overlapping
的情况,提高渲染性能.@Override public boolean hasOverlappingRendering() { return false; }
-
View.getLocationInWindow()
和View.getLocationOnScreen()
区别
// location [0]--->x坐标,location [1]--->y坐标
int[] location = new int[2];
// 获取在当前窗口内的绝对坐标,getLeft,getTop,getBottom,getRight 这一组是获取相对在它父窗口里的坐标.
view.getLocationInWindow(location);
// 获取在整个屏幕内的绝对坐标,注意这个值是要从屏幕顶端算起,也就是包括了通知栏的高度.
view.getLocationOnScreen(location);
- 如果在
Activity
的OnCreate()
事件输出那些参数,是全为0,要等UI控件都加载完了才能获取到这些.在onWindowFocusChanged(boolean hasFocus)
中获取为好. -
View.getLocationInWindow()
和View.getLocationOnScreen()
在window
占据全部screen
时,返回值相同. 不同的典型情况是在Dialog
中时,当Dialog
出现在屏幕中间时,View.getLocationOnScreen()
取得的值要比View.getLocationInWindow()
取得的值要大
- 给
cardview
加上点击效果(水波纹)layout
中增加android:foreground="?attr/selectableItemBackground"
-
Gson
解析json
数据的时候,如果json
的key
是动态的,可以用Map<String T>
来保存
- 自动导包失效
清除缓存並重启(
File
-->Invalidate Cache\Restart...
) - Android studio最实用快捷键
- Android studio使用android.os.SystemProperties方法
在Moudul的build.gradle中定义这个jar包路径,编译进应用中
def getLayoutLibPath() {
return "${android.getSdkDirectory().getAbsolutePath()}" + "/platforms/" +
android.compileSdkVersion + "/data/layoutlib.jar"
}
provided files(getLayoutLibPath())