天气预报总结
- 配置build.gradle
- 很多人没有导包就直接写代码,导致在写代码的时候报错。
- 我们写的RecyclerView、CardView是要导入support-v7包。
- RecyclerView、CardView
- DividerItemDecoration方法
在此方法里面最重要的就是onDraw方法,它根据传进来的orientation来判断制作横向item的分割线还是纵向的item的分割线。(drawVertical是纵向的item分割线,drawHorizontal是横向的item分割线)
代码如下:
- 瀑布流
瀑布流的好处:更稳定效率更高、自定义能力更强,为了实现方便,可以在item布局随意写一个高度来控制每个item的高度就行,通常这个高度都是由服务器返回的数据高度来控制的。
代码如下:
- CardView布局文件里面有两个新属性
card_view:cardCornerRadius设置圆角的半径
card_view:cardElevation设置阴影的半径
代码如下:
- Notification一共有三种通知:普通、折叠、悬挂式
在使用折叠式通知的时候,一定要使用RemoteViews创建自定义视图,然后再将自定义的视图赋值给Notification的视图。
代码如下:
//用RemoteViews来创建自定义Notification视图
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.view_fold);
//指定展开时的视图
notification.bigContentView = remoteViews;
悬挂式通知则与前面两个通知不同,它需要调用setFullScreenIntent来将Notification变为悬挂式 Notification。
PendingIntent hangPendingIntent = PendingIntent.getActivity(this, 0, hangIntent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.setFullScreenIntent(hangPendingIntent, true);
实现悬挂式Notification的完整代码如下:
Notification.Builder builder = new Notification.Builder(this);
Intent mIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://blog.csdn.net/itachi85/"));
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, mIntent, 0);
builder.setContentIntent(pendingIntent);
builder.setSmallIcon(R.drawable.foldleft);
builder.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.lanucher));
builder.setAutoCancel(true);
builder.setContentTitle("悬挂式通知");
selectNotofovatiomLevel(builder);
//设置点击跳转
Intent hangIntent = new Intent();
hangIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
hangIntent.setClass(this, NotificationActivity.class);
PendingIntent hangPendingIntent = PendingIntent.getActivity(this, 0, hangIntent, PendingIntent.FLAG_CANCEL_CURRENT);
builder.setFullScreenIntent(hangPendingIntent, true);
notificationManager.notify(2, builder.build());
以上为近期Android学习的几个知识点总结。第一次写博客,会写的不好。