圆角 多条目 滑动 imageloader

     首先Imagelodaer这块   先写依赖   

创建MyApp

public void onCreate() {
    super.onCreate();

    //初始化组件
    ImageLoaderConfiguration configuration = new ImageLoaderConfiguration.Builder(this).build();
    ImageLoader.getInstance().init(configuration);

}

设置圆角写在MainActivity的获取控件下边

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_drawlayout"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity"
    android:orientation="vertical"
    >

    <LinearLayout
        android:layout_width="300dp"

        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:background="#ff00fb"
        android:orientation="vertical">


    </LinearLayout>

    <FrameLayout
        android:id="@+id/frame"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"></FrameLayout>
    <RadioGroup
        android:id="@+id/group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <RadioButton
            android:id="@+id/frag_01"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="首页"
            android:textSize="20sp"
            android:button="@null"
            android:gravity="center"/>
        <RadioButton
            android:id="@+id/frag_02"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:text="Frag02"
            android:textSize="20sp"
            android:button="@null"
            android:gravity="center"/>
    </RadioGroup>

</android.support.v4.widget.DrawerLayout>

主界面布局

其次写frag01,list_item,list_item2

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">
    <com.bwie.xlistviewlibrary.view.XListView
        android:id="@+id/xlv"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></com.bwie.xlistviewlibrary.view.XListView>
</LinearLayout>

list_item

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="10dp"
    android:layout_margin="10dp">
    <ImageView
        android:id="@+id/imageView"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:src="@mipmap/ic_launcher"
        android:layout_gravity="center"/>

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_margin="10dp"/>
</LinearLayout>

list_item1

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:padding="10dp"
    android:layout_margin="10dp">

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView"
        android:layout_margin="10dp"/>
</LinearLayout>

MainActivity中drawLatout的监听以及设置

DrawerLayout draw = findViewById(R.id.main_drawlayout);

draw.addDrawerListener(new DrawerLayout.DrawerListener() {
    @Override
    public void onDrawerSlide(@NonNull View view, float v) {

    }

    @Override
    public void onDrawerOpened(@NonNull View view) {

    }

    @Override
    public void onDrawerClosed(@NonNull View view) {

    }

    @Override
    public void onDrawerStateChanged(int i) {

    }
});

frag01  多条慕设置   Adapter   上下啦设置

String baseUrl = "http://api.expoon.com/AppNews/getNewsList/type/1/p";
int page;
private XListView xListView;
List<Goods.DataBean> list = new ArrayList<Goods.DataBean>(); //大集合
private MAdapter mAdapter;
private ImageLoader imageLoaderInstances;

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.frag01, container, false);
    xListView = view.findViewById(R.id.xlv);
    imageLoaderInstances = ImageLoader.getInstance();
    mAdapter = new MAdapter();
    xListView.setAdapter(mAdapter);
    getNetData(0);
    xListView.setPullLoadEnable(true);  // 允许上拉加载更多;

    xListView.setXListViewListener(new XListView.IXListViewListener() {
        /**
         * 下拉---刷新
         */
        @Override
        public void onRefresh() {
            list.clear();   //清空集合
            getNetData(page);//    请求第0页,也就是服务器最新的一页数据;
            page = 0; // 把page置0;
        }

        /**
         * 上拉 --- 加载更多
         */
        @Override
        public void onLoadMore() {
            page++;
            getNetData(page);

        }
    });

    return view;

}

/**
 * 请求网络
 */
private void getNetData(int page) {
    //baseUrl = http://api.expoon.com/AppNews/getNewsList/type/1/p/

    // 拼接后 = http://api.expoon.com/AppNews/getNewsList/type/1/p/3
    new MAsyncTask().execute(baseUrl + page);
}

class MAsyncTask extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... strings) {
        return NetWordUtils.getNetjson(strings[0]);
    }

    @Override
    protected void onPostExecute(String s) {
        super.onPostExecute(s);
        Gson gson = new Gson();
        Goods goods = gson.fromJson(s, Goods.class);
        List<Goods.DataBean> dataTemp = goods.getData();
        list.addAll(dataTemp);
        //更新适配器
        mAdapter.notifyDataSetChanged();
        //让刷新头和刷新底部 消失;
        uiComplete();
    }
}


private void uiComplete() {

    xListView.stopRefresh();
    xListView.stopLoadMore();
    xListView.setRefreshTime("刚刚");
}

private class MAdapter extends BaseAdapter {

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    @Override
    public int getItemViewType(int i) {
        if (i % 2 == 0) {
            return 0;
        } else {
            return 1;
        }
    }
    @Override
    public int getCount() {
        return list.size();
    }
    @Override
    public Object getItem(int i) {
        return list.get(i);
    }
    @Override
    public long getItemId(int i) {
        return i;
    }
    public View getView(int i, View view, ViewGroup viewGroup) {
        int type = getItemViewType(i);
        switch (type) {
            case 0:
                view = View.inflate(getActivity(), R.layout.list_item, null);
                TextView textView = view.findViewById(R.id.textView);
                ImageView imageView = view.findViewById(R.id.imageView);
                textView.setText(list.get(i).getNews_title());
                //textView.setText("lcj");
                imageLoaderInstances.displayImage(list.get(i).getPic_url(), imageView,ImageBorder.border());
                break;
            case 1:
                view = View.inflate(getActivity(), R.layout.list_item1, null);
                TextView textView1 = view.findViewById(R.id.textView1);

                textView1.setText(list.get(i).getNews_title());
                //textView.setText("lcj");
                break;

        }

        return view;
    }
}

切换时候的左切

写一个ImageBorder类

public class ImageBorder {
    public  static DisplayImageOptions border(){
        DisplayImageOptions build = new DisplayImageOptions.Builder()
                .displayer(new RoundedBitmapDisplayer(100))
                .build();
        return build;
    }
}

主要是xlistviewlibray文件  导入依赖  然后是ImageLoader的依赖   gson依赖   gsonformat的使用   还有三个权限

Intent  write  read 三个权限   希望对各位能有所帮助

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值