/**
* 1, (25分) 实现ViewPager + Fragment ,切换页面, 3个Fragment;
2, (25分) 第一个Fragment中, 通过xUtils 获取网络数据, 展示到RecyclerView
地址: http://www.qubaobei.com/ios/cf/dish_list.php?stage_id=1&limit=20&page=1
解析字段: title , pic
3, (25分) 第二个Fragment 中, 属性动画, 实现机器人的: 缩放X , 移动Y , 渐 变, 旋转, 集合的效果
4, (25分) 第三个Fragment 中, 通过自定义组合控件, 实现TitleView 的效果,如 下图所示
点击按钮, 弹出吐司
*/
public class Test05Activity extends AppCompatActivity {
private ViewPager vp;
private List<Fragment> data;
private MyAdapter adapter;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test05);
vp= (ViewPager) findViewById(R.id.vp_id);
//构建ViewPager的数据源
data=new ArrayList<>();
data.add(new TestFragment_01());
data.add(new TestFragment_02());
data.add(new TestFragment_03());
//设置适配器
adapter=new MyAdapter(getSupportFragmentManager());
vp.setAdapter(adapter);
}
//自定义适配器
class MyAdapter extends FragmentPagerAdapter{
public MyAdapter(FragmentManager fm) {
super(fm);
}
@Override
public Fragment getItem(int position) {
return data.get(position);
}
@Override
public int getCount() {
return data.size();
}
}
}
public class RvAdapter extends RecyclerView.Adapter<RvAdapter.ViewHolder> {
private List<CookBook.DataBean> data;
private Context context;
public RvAdapter(Context context, List<CookBook.DataBean> data) {
this.data = data;
this.context=context;
}
public ViewHolder onCreateViewHolder(ViewGroup parent,int viewType){
//加载每个条目显示的页面
View view= LayoutInflater.from(context).inflate(R.layout.item_rv,parent);
ViewHolder viewHolder=new ViewHolder(view);
return viewHolder;
}
public void onBindViewHolder(ViewHolder holder,int position){
//赋值的操作
holder.tv.setText(data.get(position).getTitle());
//加载网络的图片
x.image().bind(holder.iv,data.get(position).getPic());
}
public int getItemCount(){
return data.size();
}
class ViewHolder extends RecyclerView.ViewHolder{
private ImageView iv;
private TextView tv;
public ViewHolder(View itemView) {
super(itemView);
this.iv= (ImageView) itemView.findViewById(R.id.iv_id);
this.tv= (TextView) itemView.findViewById(R.id.tv_id);
}
}
}
public class CustomView extends LinearLayout {
private ImageView iv;
private TextView tv;
private Button btn;
public CustomView(Context context) {
super(context);
}
public CustomView(Context context, AttributeSet attrs) {
super(context, attrs);
//引入页面,和当前的View绑定在一起
LayoutInflater.from(getContext()).inflate(R.layout.custom_view,this);
//从引入的页面中,得到控件
iv= (ImageView) findViewById(R.id.iv_id);
tv= (TextView) findViewById(R.id.tv_id);
btn= (Button) findViewById(R.id.btn_id);
//为控件设置监听器
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getContext(), "你点击了按钮", Toast.LENGTH_SHORT).show();
}
});
}
}
public class CookBook {
/**
* ret : 1
* data : [{"id":"8289","title":"油焖大虾","pic":"http://www.qubaobei.com/ios/cf/uploadfile/132/9/8289.jpg","collect_num":"1646","food_str":"大虾 葱 生姜 植物油 料酒","num":1646},{"id":"2127","title":"四川回锅肉","pic":"http://www.qubaobei.com/ios/cf/uploadfile/132/3/2127.jpg","collect_num":"1581","food_str":"猪肉 青蒜 青椒 红椒 姜片","num":1581},{"id":"30630","title":"超简单芒果布丁","pic":"http://www.qubaobei.com/ios/cf/uploadfile/132/31/30630.jpg","collect_num":"1514","food_str":"QQ糖 牛奶 芒果","num":1514},{"id":"9073","title":"家常红烧鱼","pic":"http://www.qubaobei.com/ios/cf/uploadfile/132/10/9073.jpg","collect_num":"1416","food_str":"鲜鱼 姜 葱 蒜 花椒","num":1416},{"id":"10097","title":"家常煎豆腐","pic":"