文章目录
- 模拟智慧城市(ytuCtramS)2 (主页+banner)
- 前言
- 一、启动轮播界面Banner
- 1.引入库
- 2.设置轮播XML与编写
- 二.设置轮播XML与编写
前言
第三方素材需要基于UtilsHelp
简介易学,很好的实战项目
需要资源的私聊我。
代码如下(示例):
dependencies { implementation fileTree(dir: "libs", include: ["*.jar"]) implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation fileTree(dir: 'libs', include: ['*.aar', '*.jar'], exclude: []) implementation 'com.google.android.material:material:1.1.0' implementation 'androidx.vectordrawable:vectordrawable:1.1.0' implementation 'androidx.navigation:navigation-fragment:2.1.0' implementation 'androidx.navigation:navigation-ui:2.1.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.1.0' implementation 'androidx.legacy:legacy-support-v4:1.0.0' testImplementation 'junit:junit:4.12' implementation 'androidx.cardview:cardview:1.0.0' androidTestImplementation 'androidx.test.ext:junit:1.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' }
该处使用的url网络请求的数据。
2.设置轮播XML与编写
提示:这里对文章进行总结:
例如:
提示:这里对文章进行总结:
开始编辑轮播图{MacinActivity}
public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private Banner banner; private Button butNetSet; private Button butStartHome; private SharedPreferences sharedPreferences; private SharedPreferences.Editor editor; ListbannerList = new ArrayList<>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); sharedPreferences =getSharedPreferences("data",MODE_PRIVATE); editor = sharedPreferences.edit(); initView(); } private void initView() { banner = findViewById(R.id.banner); butNetSet = findViewById(R.id.but_net_set); butStartHome = findViewById(R.id.but_start_home); butNetSet.setOnClickListener(this); butStartHome.setOnClickListener(this); bannerList.add(R.drawable.yd1); bannerList.add(R.drawable.yd2); bannerList.add(R.drawable.yd3); bannerList.add(R.drawable.yd4); bannerList.add(R.drawable.yd5); banner.setIndicator(new CircleIndicator(this)); banner.setAdapter(new BannerImageAdapter (bannerList) { @Override public void onBindView(BannerImageHolder bannerImageHolder, Integer integer, int i, int i1) { bannerImageHolder.imageView.setImageResource(integer); } },false); banner.addOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageScrolled(int i, float v, int i1) { } @Override public void onPageSelected(int i) { if(i==bannerList.size()-1){ butNetSet.setVisibility(View.VISIBLE); butStartHome.setVisibility(View.VISIBLE); }else { butNetSet.setVisibility(View.GONE); butStartHome.setVisibility(View.GONE); } } @Override public void onPageScrollStateChanged(int i) { } }); } @Override public void onClick(View v) { switch (v.getId()){ case R.id.but_net_set: UtilsHelper.alertSetIp(MainActivity.this); break; case R.id.but_start_home: Intent intent = new Intent(MainActivity.this,MainActivity2.class); startActivity(intent); finish(); break; } } @Override public void onPointerCaptureChanged(boolean hasCapture) { } }
该处使用的url网络请求的数据。
二.设置轮播XML与编写
提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
提示:这里对文章进行总结:
开始编辑轮播图{MacinActivity}
public class ShouyeFragment extends Fragment { private final int OK_ROTATION_LIST = 0x10001; private final int OK_SERVICE_LIST = 0x10002; private final int OK_PRESS_PRESS_LIST_HOT = 0x10003; private final int OK_PRESS_CATEGORY_LIST = 0x10004; private final int OK_PRESS_PRESS_LIST = 0x10005; private SearchView searchView; private CardView serchView; private Banner banner; private RecyclerView recyclerService; private RecyclerView recyclerViewHot; private TabLayout tabNews; private RecyclerView recyclerViewNews; private NetWork netWork; private RecyclerServiceAdapter recyclerServiceAdapter; private RecyclerViewHotAdapter recyclerViewHotAdapter; private ListpclbRows = new ArrayList<>(); private List pplbRows = new ArrayList<>(); private List pplbRowsHot = new ArrayList<>(); private List slbRows = new ArrayList<>(); private RecyclerNewsAdapter recyclerNewsAdapter; Handler handler = new Handler(Looper.getMainLooper()){ Gson gson = new Gson(); @Override public void handleMessage(@NonNull Message msg) { super.handleMessage(msg); switch (msg.what){ case OK_ROTATION_LIST: RotationListBean rotationListBean =gson.fromJson(msg.obj.toString(),RotationListBean.class); banner.setDatas(rotationListBean.getRows()); break; case OK_SERVICE_LIST: ServiceListBean serviceListBean = gson.fromJson(msg.obj.toString(), ServiceListBean.class); slbRows = serviceListBean.getRows(); Collections.sort(serviceListBean.getRows(), new Comparator () { @Override public int compare(ServiceListBean.RowsBean o1, ServiceListBean.RowsBean o2) { return o1.getId() - o2.getId(); } }); List slbRows = new ArrayList<>(); if(!UtilsHelper.isPad(getContext())){ if(serviceListBean.getRows().size()>9){ int i = 0; for (ServiceListBean.RowsBean slb : serviceListBean.getRows()){ if(i>=10){ break; } slbRows.add(slb); i++; } } } recyclerServiceAdapter.setDatas(slbRows); break; case OK_PRESS_PRESS_LIST_HOT: pplbRowsHot = gson.fromJson(msg.obj.toString(), PressPressListBean.class).getRows(); recyclerViewHotAdapter.setDatas(pplbRowsHot); break; case OK_PRESS_CATEGORY_LIST: Log.d("TAG", "OK_PRESS_CATEGORY_LIST: "+msg.obj.toString()); PressCategoryListBean pressCategoryListBean = gson.fromJson(msg.obj.toString(), PressCategoryListBean.class); pclbRows = pressCategoryListBean.getData(); for (PressCategoryListBean.DataBean rowsBean : pclbRows){ tabNews.addTab(tabNews.newTab().setText(rowsBean.getName())); } break; case OK_PRESS_PRESS_LIST: pplbRows = gson.fromJson(msg.obj.toString(), PressPressListBean.class).getRows(); recyclerNewsAdapter.setDatas(pplbRows); break; } } }; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View view =inflater.inflate(R.layout.fragment_shouye, container, false); netWork = new NetWork(getContext(),handler); netWork.httpGet(NetWork.ROTATION_LIST+"?type=2",OK_ROTATION_LIST); netWork.httpGet(NetWork.SERVICE_LIST,OK_SERVICE_LIST); netWork.httpGet(NetWork.PRESS_PRESS_LIST+"?hot=y",OK_PRESS_PRESS_LIST_HOT); netWork.httpGet(NetWork.PRESS_CATEGORY_LIST,OK_PRESS_CATEGORY_LIST); initView(view); return view; } private void initView(View view) { banner = view.findViewById(R.id.banner_view); recyclerService = view.findViewById(R.id.recyckerView_service); recyclerViewHot = view.findViewById(R.id.recyckerView_hot); recyclerViewNews = view.findViewById(R.id.recyckerView_news); tabNews = view.findViewById(R.id.tab_news); banner.setAdapter(new BannerImageAdapter (new ArrayList ()) { @Override public void onBindView(BannerImageHolder bannerImageHolder, RotationListBean.RowsBean rowsBean, int i, int i1) { try { Glide.with(getContext()) .load(NetWork.servicePost+rowsBean.getAdvImg()) .into(bannerImageHolder.imageView); bannerImageHolder.imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getContext(), WebViewActivity.class); intent.putExtra("id",rowsBean.getTargetId()); startActivity(intent); } }); }catch (Exception e){ Log.d("TAG","ONBindView网络错误"); } } }); banner.setIndicator(new CircleIndicator(getContext())); recyclerService.setLayoutManager(new GridLayoutManager(getContext(),UtilsHelper.isPad(getContext())? 6:5){ @Override public boolean canScrollVertically() { return false; } }); recyclerServiceAdapter = new RecyclerServiceAdapter(getContext(), new ClickPosition() { @Override public void click(int id) { switch (id){ case 9: ((MainActivity2)getActivity()).setPages(1); break; default: Intent intent = new Intent(getContext(), ServiceActivity.class); intent.putExtra("name",slbRows.get(id).getServiceName()); startActivity(intent); break; } } }); recyclerService.setAdapter(recyclerServiceAdapter); recyclerViewHot.setLayoutManager(new GridLayoutManager(getContext(),2){ @Override public boolean canScrollVertically() { return false; } }); recyclerViewHotAdapter = new RecyclerViewHotAdapter(getContext(), new ClickPosition() { @Override public void click(int i) { Intent intent = new Intent(getContext(),WebViewActivity.class); intent.putExtra("id",pplbRows.get(i).getId()); startActivity(intent); } }); recyclerViewHot.setAdapter(recyclerViewHotAdapter); tabNews.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { netWork.httpGet(NetWork.PRESS_PRESS_LIST+"?type="+pclbRows.get(tab.getPosition()).getId(),OK_PRESS_PRESS_LIST); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); recyclerViewNews.setLayoutManager(new LinearLayoutManager(getContext()){ @Override public boolean canScrollVertically() { return false; } }); recyclerNewsAdapter = new RecyclerNewsAdapter(getContext(), new ClickPosition() { @Override public void click(int i) { Intent intent = new Intent(getContext(),WebViewActivity.class); intent.putExtra("id",pplbRows.get(i).getId()); startActivity(intent); } }); recyclerViewNews.setAdapter(recyclerNewsAdapter); } }
以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)