Android Design
1.CardView
android:stateListAnimator="@drawable/touch_raise" android:foreground="?android:attr/selectableItemBackground" app:cardBackgroundColor="#909090" app:cardCornerRadius="10dp" app:cardElevation="2dp" app:cardMaxElevation="10dp"
res\drawable\touch_raise.xml
2.新增动画
波纹效果(Ripple):当你使用了Material主题后,波纹动画会自动应用在所有的控件上。
可以设置其属性调整效果:
android:background=?android:attr/selectableItemBackground波纹有边界
或
android:background=?android:attr/selectableItemBackgroundBorderless波纹超出边界
设置颜色(可以通过设置xml属性来调节动画颜色)
android:colorControlHighlight //设置波纹颜色
android:colorAccent //设置checkbox等控件的选中颜色
圆形动画(Circular Reveal):
Animator circularReveal = ViewAnimationUtils.createCircularReveal(mOval, mOval.getWidth() / 2, mOval.getHeight() / 2, mOval.getWidth(), 0); /** *view 操作的视图 *centerX 动画开始的中心点X *centerY 动画开始的中心点Y *startRadius 动画开始半径 *startRadius 动画结束半径 */ circularReveal.setInterpolator(new AccelerateDecelerateInterpolator()); //设置动画插值器 加速度 circularReveal.setDuration(1000); circularReveal.start();
3.颜色采集
BitmapDrawable drawable = (BitmapDrawable) mImage.getDrawable(); Bitmap bitmap = drawable.getBitmap(); //Palette 颜色采集 Palette.Builder from = Palette.from(bitmap); //传入默认颜色 如果无法采集到该色值 使用默认 Palette generate = from.generate(); int darkVibrantColor = generate.getLightVibrantColor(Color.BLACK); //转ARGB String s = Integer.toHexString(darkVibrantColor); //替换透明度 String ff = s.replaceFirst("ff", "22"); //组织颜色 darkVibrantColor= Color.parseColor("#" + ff); // 异步创建/* from.generate(new Palette.PaletteAsyncListener() { @Override public void onGenerated(Palette palette) { ARGB } });*/ mTitle.setBackgroundColor(darkVibrantColor);
4.RecyclerView控件
LayoutManager布局管理器:
//1、设置布局管理器 ,确认我们的布局管理器 LinearLayoutManager manager = new LinearLayoutManager(this,LinearLayoutManager.VERTICAL,false); //LinearLayoutManager 线性管理器// GridLayoutManager manager = new GridLayoutManager(this,3,GridLayoutManager.VERTICAL,false); //GridLayoutManager 网格管理器// StaggeredGridLayoutManager manager = new StaggeredGridLayoutManager(3,StaggeredGridLayoutManager.HORIZONTAL); //StaggeredGridLayoutManager 交错网格管理器|瀑布流 mRecycle.setLayoutManager(manager);
RecycleView.Adapter 适配器:
class MyAdapter extends RecyclerView.Adapter{ //Adapter.ViewHolder 适配器持有者 /** * 创建ViewHolder * @param parent * @param viewType * @return */ @Override public Holder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_recycle, parent, false); return new Holder(view); } /** * 绑定视图 类似于 getView * @param holder * @param position */ @Override public void onBindViewHolder(Holder holder, int position) { holder.text.setText(String.valueOf(position)); } /** * 子元素个数 * @return */ @Override public int getItemCount() { return 100; } /** * 记录 */ class Holder extends RecyclerView.ViewHolder{ TextView text; public Holder(View itemView) { super(itemView); text = (TextView) itemView.findViewById(R.id.item_text); } }}
5.