ListView(列表效果)
第一步:构建初始化

第二步:创建listItem格式
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-OLs29f5s-1650984462765)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220425235414969.png)]](https://img-blog.csdnimg.cn/78e2a1585ff749d7a415f94192b7bd8f.png)
第三步:创建准备得测试类

第四步:创建视图与数据得桥梁MyAdpater并继承BaseAdapter
public class MyAdpater extends BaseAdapter {
private List<Test> testList;
private Context context;
@Override
public int getCount() {
return testList.size();
}
@Override
public Object getItem(int i) {
return null;
}
@Override
public long getItemId(int i) {
return i;
}
@Override
public View getView(int i, View view, ViewGroup viewGroup) {
ViewHolder viewHolder;
if (view == null){
viewHolder = new ViewHolder();
view= LayoutInflater.from(context).inflate(R.layout.list_item,viewGroup,false);
viewHolder.textView=view.findViewById(R.id.listItem);
view.setTag(viewHolder);
}else{
viewHolder=(ViewHolder) view.getTag();
}
viewHolder.textView.setText(testList.get(i).getName());
return view;
}
public MyAdpater(List<Test> testList, Context context) {
this.testList = testList;
this.context = context;
}
private final class ViewHolder{
TextView textView;
}
}
效果图:

RecyclerView(灵活列表效果)
整体架构

item代码

MainActivity中代码

此处监听Item被点击与ListView有所差别,MyAdpater中代码
public class MyAdpater extends RecyclerView.Adapter<MyAdpater.MyViewHolder> {
private List<Test> testList;
private Context context;
@NonNull
@Override
public MyViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view=View.inflate(context,R.layout.recyclerview_item,null);
return new MyViewHolder(view);
}
@Override
public void onBindViewHolder(@NonNull MyViewHolder holder, int position) {
holder.tv.setText(testList.get(position).getName());
}
@Override
public int getItemCount() {
return testList == null? 0 : testList.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
private TextView tv;
public MyViewHolder(@NonNull View itemView) {
super(itemView);
tv=itemView.findViewById(R.id.listItem);
itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (mOnItemClickListener !=null ){
mOnItemClickListener.onRecyclerItemClick(getAdapterPosition());
}
}
});
}
}
public MyAdpater(List<Test> testList, Context context) {
this.testList = testList;
this.context = context;
}
private OnRcyclerItemClickListener mOnItemClickListener;
public void setRecyclerItemClickListener(OnRcyclerItemClickListener listener){
mOnItemClickListener =listener;
}
public interface OnRcyclerItemClickListener{
void onRecyclerItemClick(int postion);
}
}
动画类型
- 逐帧动画(frame-by-frame animation)
- 补间动画(tweened animation)
- 属性动画(property animation)
逐帧动画
animation-list

动画的启动和停止
//获取动画的Drawable资源
AnimationDrawable anim=(AnimationDrawable)relativeLayout.getBackground();
//启动动画
anim.start();
//停止动画
anim.stop;

补间动画
- alpha 透明度
- rotate 旋转
- scale 缩放
- translate 平移
透明 
旋转

缩放 
平移

activtiy

最终效果

属性动画
ValueAnimator
![[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-T03V17on-1650984462770)(C:\Users\Administrator\AppData\Roaming\Typora\typora-user-images\image-20220426222707424.png)]](https://img-blog.csdnimg.cn/e482c4c7d2114e2e9dceb8a91045a21c.png)
ObjectAnimator


监听器
onAnimationStart()动画开始的时候调用
onAnimationEnd()动画结束的时候调用
onAnimationCancel()动画被取消的时候调用
onAnimationRepeat()动画重复执行的时候调用
 此处主要效果就是字体渐渐显示出来,由透明转显示
|