PullRefresh(上拉下拉)添加头布局Banner
来源:互联网 发布:2k帕森斯脸型数据 编辑:程序博客网 时间:2024/05/27 10:43
XMl文件:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.yuekao_zonghe.Fragment.Frag3"> <com.handmark.pulltorefresh.library.PullToRefreshListView android:id="@+id/f3_pull" android:layout_width="fill_parent" android:layout_height="fill_parent" android:cacheColorHint="#00000000" android:divider="#19000000" android:dividerHeight="4dp" android:fadingEdge="none" android:fastScrollEnabled="false" android:footerDividersEnabled="false" android:headerDividersEnabled="false" android:smoothScrollbar="true" /></LinearLayout>
Banner-xml文件:
<?xml version="1.0" encoding="utf-8"?><android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> <com.youth.banner.Banner android:layout_width="fill_parent" android:layout_height="200dp" android:id="@+id/f3_banner"></com.youth.banner.Banner></android.support.constraint.ConstraintLayout>
主代码:
import android.content.Context;import android.os.AsyncTask;import android.os.Bundle;import android.support.annotation.Nullable;import android.support.v4.app.Fragment;import android.view.LayoutInflater;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.ImageView;import android.widget.ListView;import android.widget.TextView;import com.example.yuekao_zonghe.Bean.BannerData;import com.example.yuekao_zonghe.R;import com.example.yuekao_zonghe.Utile.ImageloaderUtile;import com.example.yuekao_zonghe.Utile.NetUtil;import com.google.gson.Gson;import com.handmark.pulltorefresh.library.PullToRefreshBase;import com.handmark.pulltorefresh.library.PullToRefreshListView;import com.nostra13.universalimageloader.core.ImageLoader;import com.youth.banner.Banner;import java.util.ArrayList;import java.util.Arrays;import java.util.List;public class Frag3 extends Fragment { public String urlString = "http://api.expoon.com/AppNews/getNewsList/type/3/p/1"; String[] girls={ "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511397748&di=fc26b4d019d84cae9afced694119e013&imgtype=jpg&er=1&src=http%3A%2F%2Fnews.cnhubei.com%2Fxw%2Fyl%2F201405%2FW020140530279662501386.jpg", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511397780&di=553cd77bbefc58fad19f429490fd21ba&imgtype=jpg&er=1&src=http%3A%2F%2Fwww.sh.xinhuanet.com%2F136259092_14939501519491n.jpg", "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=471800453,1621863142&fm=11&gp=0.jpg", "https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1511397838&di=8b4ca4c35c11ca874b006590c015c455&imgtype=jpg&er=1&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimgad%2Fpic%2Fitem%2F8cb1cb13495409237adfa6e39858d109b2de49fd.jpg", "https://ss0.bdstatic.com/70cFuHSh_Q1YnxGkpoWK1HF6hhy/it/u=551001357,2523081847&fm=27&gp=0.jpg" }; ArrayList<BannerData.DataBean> list = new ArrayList<>(); private Banner banner; private PullToRefreshListView pull; private Myadpater md; @Nullable @Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { //获取控件 View view = inflater.inflate(R.layout.activity_frag3, null); View view2 = View.inflate(getActivity(), R.layout.bannerdata, null); //获取pull控件 pull = view.findViewById(R.id.f3_pull); //允许下拉上拉 pull.setMode(PullToRefreshBase.Mode.BOTH); //获取底层的listview ListView listView = pull.getRefreshableView(); //添加头布局 listView.addHeaderView(view2); //监听事件 pull.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ListView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ListView> refreshView) { list.clear(); getData(); } @Override public void onPullUpToRefresh(PullToRefreshBase<ListView> refreshView) { getData(); } }); banner = view2.findViewById(R.id.f3_banner); banner.setImageLoader(new MyBanner());//加载图片的类 banner.setImages(Arrays.asList(girls));//加入图片- banner.start();//开启轮播 //适配器 md = new Myadpater(); pull.setAdapter(md); //获取网络数据 getData(); return view; } //获取网络数据的方法 private void getData() { new MyAsynctask().execute(urlString); } //适配器 private class Myadpater extends BaseAdapter { @Override public int getCount() { return list.size(); } @Override public Object getItem(int i) { return null; } @Override public long getItemId(int i) { return 0; } @Override public View getView(int i, View view, ViewGroup viewGroup) { if (view == null) { view = View.inflate(getActivity(), R.layout.bannerdatatext, null); } ImageView img = view.findViewById(R.id.f3_img); ImageLoader.getInstance().displayImage(list.get(i).getPic_url(), img, ImageloaderUtile.getDisplayImageOption()); TextView textView = view.findViewById(R.id.f3_text); textView.setText(list.get(i).getNews_title()); return view; } } //获取网络数据 private class MyAsynctask extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... strings) { return NetUtil.getNetJson(strings[0]); } @Override protected void onPostExecute(String s) { super.onPostExecute(s); Gson gson = new Gson(); BannerData bannerData = gson.fromJson(s, BannerData.class); List<BannerData.DataBean> data = bannerData.getData(); list.addAll(data); //刷新适配器 md.notifyDataSetChanged(); //停止刷新 pull.onRefreshComplete(); } } private class MyBanner extends com.youth.banner.loader.ImageLoader { @Override public void displayImage(Context context, Object path, ImageView imageView) { ImageLoader.getInstance().displayImage((String) path,imageView); } }}
阅读全文
0 0
- PullRefresh(上拉下拉)添加头布局Banner
- 安卓开发中Banner添加头布局结合PullToRefresh实现上拉下拉
- PullToRefreshListView的添加Banner头布局
- 上拉下拉电阻
- spi 上拉下拉
- 上拉下拉电阻
- RecyclerView上拉下拉
- PullOnrefreshListView上拉下拉
- pulltorefresh上拉下拉
- XListView上拉下拉
- pulltorefreshdemo 上拉下拉
- 上拉下拉加载
- XRecyclerView上拉下拉
- PullToRefreshListView上拉下拉
- Tablayout与Viewpager里添加Xlistview实现上拉下拉
- android 上拉下拉刷新和banner轮播广告条 Github 项推荐
- XRecyclerView如此so easy实现下拉刷新,上拉加载,添加头布局(头布局任意加)
- ListView上拉下拉刷新
- 打酱油 Java算法
- mysql 数据库导库命令
- 连接集群的配置:
- mysql服务安装
- 8. 广义表的建立与基本操作
- PullRefresh(上拉下拉)添加头布局Banner
- 利用ajax实现前台javascript同c#后台MVC下的aspx.cs文件传递数据的两种方法2
- 剑桥AI公司:7天精通一门新语言,未来将学会7000种语言
- PopupWindow
- 数据模型
- Win7下安装HBase
- The type java.io.ObjectInputStream cannot be resolved.
- 什么时装饰者模式,什么是适配器模式
- MultiDex解决64K限制的问题