您的位置:首页 > 理论基础 > 计算机网络

写一篇博客记录个人这段时间的学习心得 我的github:https://github.com/w1232101/

2016-08-22 17:29 519 查看
学习杂记:

Toolbar+DrawerLayout+ActionBarDrawerToggle(侧滑条目的按键)+NavigationView(侧滑的container):

然后点击之后切换fragment套ViewPager再套fragment就要用getChildFragmentManager:FragmentPagerAdapter | FragmentStatePagerAdapter

SwipeToLoadLayout :用法

1. compile 'com.github.Aspsine:SwipeToLoadLayout:v1.0.2'
2.xml:
<com.aspsine.swipetoloadlayout.SwipeToLoadLayout xmlns:android="http://schemas.android.com/apk/res/android"
app:swipe_style="classic">
<include
android:id="@id/swipe_refresh_header"
layout="@layout/layout_refresh_header" />
<android.support.v7.widget.RecyclerView
android:paddingLeft="6dp"
android:id="@+id/swipe_target"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<include
android:id="@id/swipe_load_more_footer"
layout="@layout/layout_refresh_footer" />
</com.aspsine.swipetoloadlayout.SwipeToLoadLayout>
3.public class TwitterRefreshHeaderView extends SwipeRefreshHeaderLayout{@Override onRefresh() {;@Override onSwipe(int y, boolean isComplete)@Override complete() {
4.public class ClassicLoadMoreFooterView extends SwipeLoadMoreFooterLayout {//复写加载动画和相应处理
5. 在activity中设置点击事件
swipeToLoadLayout.setOnRefreshListener(this);
swipeToLoadLayout.setOnLoadMoreListener(this);


RecyclerView使用瀑布流:StaggeredGridLayoutManager :

StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
swipeTarget.setLayoutManager(staggeredGridLayoutManager);
swipeTarget.setItemAnimator(new DefaultItemAnimator());


ViewPager+TabLayout

GankMM:MyApplication缓存策略可以参考! 代码使用retrofit+okhttp+Glide加载图片+RecyclerView(StaggeredGridLayoutManager)瀑布流

http://www.cnblogs.com/_franky/archive/2011/11/23/2260109.html okhttp缓存策略

Snackbar:android类似toast效果的一个东西!  Snackbar snackbar = Snackbar.make(view, message, Snackbar.LENGTH_SHORT);
ColoredSnackbar.defaultInfo(snackbar).show();
Glide 加载图片ImageView
Glide.with(context)
.load(url)
.placeholder(R.drawable.pic_gray_bg)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(viewHolder.image)
.thumbnail(0.2f)///这个属性代表缩略显示比例!也可以不写;


Picasso加载圆角图片(原生的ImageView)
int size = resources.getDimensionPixelOffset(R.dimen.hero_avatar_size);50dp
int width = resources.getDimensionPixelOffset(R.dimen.hero_avatar_border);3dp
Picasso.with(parent.getContext())
.load(character.getAvatar())
.resize(size, size)
.transform(new CircleTransformation(width))
.into(holder.ivAvatar);


SVProgressHUD :自定义加载的进度条控件,GankMM里面保存文件用过 com.bigkoo:svprogresshud:1.0.2

用法

public void showProgressDialog() {
mSVProgressHUD = new SVProgressHUD(getActivity());
if (mSVProgressHUD.isShowing()) {
mSVProgressHUD.dismiss();
}
mSVProgressHUD.showWithStatus("加载中...", SVProgressHUD.SVProgressHUDMaskType.BlackCancel);
}


retrofit导包:具体使用:

http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2016/0504/4208.html
compile 'com.squareup.okhttp3:okhttp:3.3.1'
compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'


自定义View基础:

http://blog.csdn.net/aigestudio/article/details/42677973

Canvas save表示添加stack进入Canvas栈 和 restore 表示弹出上一个save的栈;

restoreToCount(int saveCount)方法来指定在还原的时候还原哪一个保存操作

动画 canvas.save(Canvas.MATRIX_SAVE_FLAG);

canvas.skew(float sx, float sy)错切方法

canvas.rotate(5);

translate(float dx, float dy):translate方法会改变画布的原点坐标

scale(float sx, float sy)缩放也很好理解,但是它有一个重载方法

scale(float sx, float sy, float px, float py):后两个参数用于指定缩放的中心点,前两个参数用于指定横纵向的缩放比率值在0-1之间为缩小:

利用matrix操作动画:

canvas.save(Canvas.MATRIX_SAVE_FLAG);

Matrix matrix = new Matrix();

matrix.setScale(0.8F, 0.35F);

matrix.postTranslate(100, 100);

canvas.setMatrix(matrix);

canvas.drawBitmap(mBitmap, 0, 0, null);

canvas.restore();

View|ViewGroup 的onMeasure() http://blog.csdn.net/aigestudio/article/details/42989325

http://www.open-open.com/lib/view/open1437312265428.html

Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用:

http://blog.csdn.net/feiduclear_up/article/details/46500865

android改进的scrollView: NestedScrolling ;app:layout_scrollFlags=”scroll|exitUntilCollapsed”

CoordinatorLayout(一个增强型的FrameLayout)+AppBarLayout+CollapsingToolbarLayout:配套使用

计时器/倒计时

Handler与Runnable(最简单型)
SimpleDateFormat sDateFormat = new SimpleDateFormat("HH:mm:ss");
String[] date = sDateFormat.format(new Date()).split(":");
hour = Integer.parseInt(date[0]);
min = Integer.parseInt(date[1]);
sec = Integer.parseInt(date[2]);
bt.setText(hour + ":" + min + ":" + sec);
handler.postDelayed(runnable, 1000);
public void run() {
if (sec == 59) {
sec = 0;
if (min == 59) {
min = 00;
if (hour == 23) {
hour = 0;
} else {
hour++;
}
} else {
min++;
}
} else {
sec++;
}
bt.setText((hour<10?"0"+hour:hour) + ":" + (min<10?"0"+min:min) + ":" + (sec<10?"0"+sec:sec));


流式布局标签在FlowLayout-master:添加FlowLayout-lib依赖就行了:

2.popupWindow.showAsDropDown(findViewById(R.id.ll), 0, 0);
showAsDropDown,例如:showAsDropDown(MainActivity.this.findViewById(R.id.logo_iv),100,0),
以R.id.logo_iv的左下角为原点,向X轴正方向偏移100个像素,Y轴方向偏移0个像素。
注意:这个偏移量可以是正的,也可以是负的。无论偏移多大,pw是不会跑出屏幕。


Listview支持多种Item,只需要重写两个方法: getViewTypeCount()、 getItemViewType(int)。在getView中一开始就判断getItemViewType
例如:if(getItemViewType(position)==1){
if(convertView==null){
xxxx;
}else{
holder = xx.getTag();
}
xxxxx;
}else if(getItemViewType(position)==2){
}


zhy的commonRecycleViewAdapter库:支持区分itemtype

图片添加阴影效果:

imageView.setColorFilter(Color.parseColor("#77000000"));清除就用clearColorFilter();
// 设置背景颜色变暗
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.alpha = .3f;
getWindow().setAttributes(lp);


侧滑删除菜单实现的两种方式:

1.使用Reveal动画
2.在listview的条目布局包裹一层 horizontalScrollView


shift + ins(0):linux 粘贴快捷键
git操作总结:
建一个文件夹:
git init
git config --global user.name "Your Name"
git config --global user.email you@example.com
git clone 代码url
git add .
git commit -m "dasdasd"
git push -u origin master
如果提交发现远程做了新修改
git pull(没冲突就再push 一次)
如果有冲突:
git diff:找到冲突的文件,解决冲突!
git commit -a -m 'Resolved conflict'


Android 6.0机型权限适配! 动态权限设置动态获取,低版本不会弹出这个:

http://blog.csdn.net/wei_zhi/article/details/51154570

如果权限没在xml配置,可以在代码中弹出dialog配置

final private int REQUEST_CODE_ASK_PERMISSIONS = 123;
private void insertDummyContactWrapper() {
//检查AndroidManiFest中是否配置了WRITE_CONTACTS权限
int hasWriteContactsPermission = checkSelfPermission(Manifest.permission.WRITE_CONTACTS);
//若未配置该权限
if (hasWriteContactsPermission != PackageManager.PERMISSION_GRANTED) {
//申请配置该权限
requestPermissions(new String[] {Manifest.permission.WRITE_CONTACTS},
REQUEST_CODE_ASK_PERMISSIONS);
//直接返回,不执行insertDummyContact()方法
return;
}
//若配置了该权限,才能调用方法
insertDummyContact();
}
requestPermissions会调用onRequestPermissionsResult(as的activity复写这个方法)
对于 “不再询问”(“Never Ask Again”),调用Activity.shouldShowRequestPermissionRationale()


自定义View:http://blog.csdn.net/singwhatiwanna/article/details/38426471

view绘制流程:

1.performMeasure -> measure -> onMeasure
2.performLayout -> layout -> onLayout
3.performDraw -> draw -> onDraw


一:measure:源码:

case ViewGroup.LayoutParams.MATCH_PARENT: //代表MeasureSpec.EXACTLY
measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.EXACTLY);
break;
case ViewGroup.LayoutParams.WRAP_CONTENT:  //代表MeasureSpec.AT_MOST
measureSpec = MeasureSpec.makeMeasureSpec(windowSize, MeasureSpec.AT_MOST);
break;
default:   //100dp 等精确的数值 代表MeasureSpec.EXACTLY
measureSpec = MeasureSpec.makeMeasureSpec(rootDimension, MeasureSpec.EXACTLY);
break;


采用 view.measure 去提前获取 view 的宽高,根据 view 的 layoutParams 来分

match_parent

直接放弃,无法 measure 出具体的宽高

具体的数值( dp/px )

比如宽高都是 100px ,如下 measure :
int widthMeasureSpec = MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY);
view.measure(widthMeasureSpec, heightMeasureSpec);
wrap_content
如下 measure :
wrap_content
int widthMeasureSpec = MeasureSpec.makeMeasureSpec( (1 << 30) - 1, MeasureSpec.AT_MOST);
int heightMeasureSpec = MeasureSpec.makeMeasureSpec( (1 << 30) - 1, MeasureSpec.AT_MOST);
view.measure(widthMeasureSpec, heightMeasureSpec);


注意到(1 << 30) - 1,通过分析MeasureSpec的实现可以知道,view的尺寸使用30位二进制表示的,也就是说最大是30个1即 2^30 - 1,也就是(1 << 30) - 1,在最大化模式下,我们用view理论上能支持的最大值去构造MeasureSpec是合理的。

二、layout

当 viewgroup 的位置被确定后,它在 onLayout 会遍历所有的 child 并调用其 layout 。在 layout 中 onLayout 会被调用。
水波纹的实现思想://找到点击的view,获取宽高,裁剪矩形,然后绘制圆
canvas.save();
canvas.clipRect(left, top, right, bottom);
canvas.drawCircle(mCenterX, mCenterY, mRevealRadius, mPaint);
canvas.restore();


draw

View 的 draw 过程

draw 的大致流程

a. 画背景  background.draw(canvas)
b. 绘制自己( onDraw )
c. 绘制 children ( dispatchDraw )
d. 绘制装饰( onDrawScrollBars )


ViewPager+Fragment:预加载问题!!
setOffscreenPageLimit(2);2代表除去当前显示页面以外需要被预加载的页面数。size-1;控制页面缓存的页数!


拖拽控件:DragSortlistView DragSortGridView

刷新与加载使用 SwipeRefreshLayout

https://github.com/kodyan/SwipeRefreshLayout

夜间模式,app换肤的本质就是将控件的颜色属性抽取成attr的引用,进一步抽取成style

自定义View的移动动画的实现:

1.setPadding或者直接改变LayoutParams,使用属性的值动画;
2.Scroller 记得用invalidate
3.layout(x,x,x,x);配合使用值动画或者补间动画
TranslateAnimation taa = new TranslateAnimation(0, 0, left + 200,
initLeft + 200);
taa.setDuration(200);
TranslateAnimation ta = null;
// 开启移动动画
ta = new TranslateAnimation(inner.getLeft(), normal.left, 0, 0);
ta.setDuration(200);
inner.startAnimation(ta);
// 设置回到正常的布局位置
inner.layout(normal.left, normal.top, normal.right, normal.bottom);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  博客