自定义梯形view与XRecyclerView的结合

 
 
一。http(工具类)

1.
HttpConfig
public class HttpConfig {
    public static String goods_url="http://ttpc.dftoutiao.com/jsonpc/refresh";
    public static final int TYPE1 = 3;//条目是三张图
    public static final  int TYPE2 = 1;//条目是1张图

}

 
2.OkLoadListener
  

public interface OkLoadListener { void okLoadSuccess(String json); void okLoadError(String error);}
  3.AppUtil(自定义view)
public class AppUtil {
    /**
     *
     * @param context
     * @return 屏幕宽度
     */
    public static int screenWidth(Context context){
        DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        return  metrics.widthPixels;
    }
}
   4.NetWorkUtil(网络连接)
public class NetWorkUtil {

    /**
     *
     * @return 是否有活动的网络连接
     */
    public final static boolean hasNetWorkConnection(Context context){
        //获取连接活动管理器
        final ConnectivityManager connectivityManager= (ConnectivityManager) context.
                getSystemService(Context.CONNECTIVITY_SERVICE);
        //获取链接网络信息
        final NetworkInfo networkInfo=connectivityManager.getActiveNetworkInfo();

        return (networkInfo!= null && networkInfo.isAvailable());

    }
    /**
     * @return 返回boolean ,是否为wifi网络
     *
     */
    public final static boolean hasWifiConnection(Context context)
    {
        final ConnectivityManager connectivityManager= (ConnectivityManager) context.
                getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo networkInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        //是否有网络并且已经连接
        return (networkInfo!=null&& networkInfo.isConnectedOrConnecting());


    }

    /**
     * @return 返回boolean,判断网络是否可用,是否为移动网络
     *
     */

    public final static boolean hasGPRSConnection(Context context){
        //获取活动连接管理器
        final ConnectivityManager connectivityManager= (ConnectivityManager) context.
                getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo networkInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
        return (networkInfo!=null && networkInfo.isAvailable());

    }
    /**
     * @return  判断网络是否可用,并返回网络类型,ConnectivityManager.TYPE_WIFI,ConnectivityManager.TYPE_MOBILE,不可用返回-1
     */
    public static final int getNetWorkConnectionType(Context context){
        final ConnectivityManager connectivityManager=(ConnectivityManager) context.
                getSystemService(Context.CONNECTIVITY_SERVICE);
        final NetworkInfo wifiNetworkInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
        final NetworkInfo mobileNetworkInfo=connectivityManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE);


        if(wifiNetworkInfo!=null &&wifiNetworkInfo.isAvailable())
        {
            return ConnectivityManager.TYPE_WIFI;
        }
        else if(mobileNetworkInfo!=null &&mobileNetworkInfo.isAvailable())
        {
            return ConnectivityManager.TYPE_MOBILE;
        }
        else {
            return -1;
        }


    }


}
   5.HttpUtils(请求工具)
public class HttpUtils {
    private static final String TAG = "HttpUtils-----";
    private static HttpUtils httpUtils;
    private final int SUCCESS = 0;
    private final int ERROR = 1;
    private MyHandler myHandler = new MyHandler();
    private OkLoadListener okLoadListener;

    public static HttpUtils getHttpUtils() {
        if (httpUtils == null) {
            httpUtils = new HttpUtils();
        }
        return httpUtils;
    }

    class MyHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case SUCCESS:
                    //成功
                    String json = (String) msg.obj;
                    okLoadListener.okLoadSuccess(json);
                    break;

                case ERROR:
                    //失败
                    String error = (String) msg.obj;
                    okLoadListener.okLoadError(error);
                    break;
            }
        }
    }

    //get
    public void okGet(String url) {
        OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new MyIntercepter()).build();

        Request request = new Request.Builder().url(url).build();
        Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message = myHandler.obtainMessage();
                message.what = ERROR;
                message.obj = e.getMessage();
                myHandler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Message message = myHandler.obtainMessage();
                message.what = SUCCESS;
                message.obj = response.body().string();
                myHandler.sendMessage(message);
            }
        });
    }

    public void setOkLoadListener(OkLoadListener okLoadListener) {
        this.okLoadListener = okLoadListener;
    }

    //post
    public void okPost(String url, Map<String, String> params) {
        OkHttpClient okHttpClient = new OkHttpClient.Builder().addInterceptor(new MyIntercepter()).build();

        FormBody.Builder builder = new FormBody.Builder();
        Set<String> keySet = params.keySet();
        for (String key :
                keySet) {
            String value = params.get(key);
            builder.add(key, value);
        }
        FormBody formBody = builder.build();
        Request request = new Request.Builder().url(url).post(formBody).build();
        Call call = okHttpClient.newCall(request);

        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Message message = myHandler.obtainMessage();
                message.what = ERROR;
                message.obj = e.getMessage();
                myHandler.sendMessage(message);
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Message message = myHandler.obtainMessage();
                message.what = SUCCESS;
                message.obj = response.body().string();
                myHandler.sendMessage(message);
            }
        });

    }

    //拦截器
    class MyIntercepter implements Interceptor {
        //intercept 拦截
        @Override
        public Response intercept(Chain chain) throws IOException {
            //添加公共参数
//            post 取出原来所有的参数,将之加到新的请求体里面。然后让请求去执行
            Request request = chain.request();
            //获取请求方法
            String method = request.method();
            if (method.equals("GET")) {//---------------------------GET 拦截
                //取出url地址
                String url = request.url().toString();
                //拼接公共参数
                boolean contains = url.contains("?");
                if (contains) {
                    url = url + "&source=android";
                } else {
                    url = url + "?source=android";
                }

                Request request1 = request.newBuilder().url(url).build();

                Response response = chain.proceed(request1);

                return response;


            } else if (method.equals("POST")) {//---------------------POST 拦截
                RequestBody body = request.body();//请求体
                if (body instanceof FormBody) {
                    //创建新的请求体
                    FormBody.Builder newBuilder = new FormBody.Builder();
                    for (int i = 0; i < ((FormBody) body).size(); i++) {
                        String key = ((FormBody) body).name(i);
                        String value = ((FormBody) body).value(i);
                        newBuilder.add(key, value);
                    }
                    //添加公共参数
                    newBuilder.add("source", "android");
                    FormBody newBody = newBuilder.build();
                    //创建新的请求体
                    Request request1 = request.newBuilder().post(newBody).build();
                    //去请求
                    Response response = chain.proceed(request1);
                    return response;
                }
            }
            return null;
        }
    }

    //上传文件(图片)
    public void upLoadImage(String url, String path) {//url 要上传的地址。path 要上传的文件路径
        //媒体类型
        MediaType mediaType = MediaType.parse("image/*");
        //multipartbody
        MultipartBody.Builder builder = new MultipartBody.Builder().setType(MultipartBody.FORM);
        File file = new File(path);
        MultipartBody multipartBody = builder.addFormDataPart("file", file.getName(), RequestBody.create(mediaType, file)).build();

        OkHttpClient okHttpClient = new OkHttpClient();
        Request request = new Request.Builder().url(url).post(multipartBody).build();
        Call call = okHttpClient.newCall(request);
        call.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                Log.d(TAG, "上传失败0----: ");
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.d(TAG, "上传成功: ");
            }
        });

    }
}
二.dbsqlite(数据库)
   1.DbHelper 
public class DbHelper extends SQLiteOpenHelper{

    //数据库文件名称
    private static final String DB_NAME = "news.db";
    public static final String NEWS_TABLE_NAME = "news";
    private static final int VERSION = 1;
    public DbHelper(Context context) {
        super(context, DB_NAME, null, VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table " + NEWS_TABLE_NAME + " (_id Integer PRIMARY KEY ,json text)";

        db.execSQL(sql);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}

三.model


  1. GoodsListener
public interface GoodsListener {
    void getSuccess(String json);
    void getError(String error);
}

   2.IModel
public interface IModel {
    public void getGoodsListData(String url, Map<String,String> map,GoodsListener goodsListener);

}

  3.ModelImpl 
public class ModelImpl implements IModel{
    @Override
    public void getGoodsListData(String url, Map<String, String> map, final GoodsListener goodsListener) {

        HttpUtils httpUtils = HttpUtils.getHttpUtils();
        httpUtils.okPost(url,map);
        httpUtils.setOkLoadListener(new OkLoadListener() {
            @Override
            public void okLoadSuccess(String json) {

                goodsListener.getSuccess(json);
            }

            @Override
            public void okLoadError(String error) {
                goodsListener.getError(error);
            }
        });
    }
}

四.presenter

  1.IPresenter
public interface IPresenter {
    void showGoodsListToView(IModel iModel, IMainView iMainView);
}

  2.PresenterImpl 
public class PresenterImpl implements IPresenter{
    private static final String TAG = "PresenterImpl-----";
    @Override
    public void showGoodsListToView(IModel iModel, final IMainView iMainView) {
                Map<String,String> map = new HashMap<>();
                map.put("type",iMainView.getContent()+"");
                iModel.getGoodsListData(HttpConfig.goods_url, map, new GoodsListener() {
                    @Override
                    public void getSuccess(String json) {
                        if(!TextUtils.isEmpty(json)){
                            String s = json.replace("null(", "").replace(")", "");
                            Log.d(TAG, "数据----: "+s);
                            UserBean userBean = new Gson().fromJson(s,UserBean.class);
                            iMainView.showGoodsList(userBean);
                        }
                    }

                    @Override
                    public void getError(String error) {
                        Log.d(TAG, "getError: "+error);
                    }
                });
    }
}

五.bean

  1.UserBean(演示bean包)
public class UserBean {

    public String stat;
    public List<Data> data;

    public String getStat() {
        return stat;
    }

    public void setStat(String stat) {
        this.stat = stat;
    }

    public List<Data> getData() {
        return data;
    }

    public void setData(List<Data> data) {
        this.data = data;
    }

    public class Data {
        public String topic;
        public String source;
        public List<IMG> miniimg;

        public String getTopic() {
            return topic;
        }

        public void setTopic(String topic) {
            this.topic = topic;
        }

        public String getSource() {
            return source;
        }

        public void setSource(String source) {
            this.source = source;
        }

        public List<IMG> getMiniimg() {
            return miniimg;
        }

        public void setMiniimg(List<IMG> miniimg) {
            this.miniimg = miniimg;
        }

        public class IMG {
            public String src;

            public String getSrc() {
                return src;
            }

            public void setSrc(String src) {
                this.src = src;
            }
        }

    }
}

六.view
  
   1.ThreeColorView (自定义view)
public class ThreeColorView extends ViewGroup{
    public ThreeColorView(Context context) {
        super(context);
    }

    public ThreeColorView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ThreeColorView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        //此控件的高度
        int totalHeight = 0;
        //此控件的宽度
        int totalWidth = 0;
        //得到子view数量
        int child = getChildCount();
        if(child > 0){
            for (int i = 0; i < child; i++) {//遍历子控件
                //得到此容器所有的子view
                View view = getChildAt(i);
                totalHeight += view.getMeasuredHeight();
                measureChild(view,widthMeasureSpec,heightMeasureSpec);
            }
        }
       totalWidth = AppUtil.screenWidth(getContext());
        System.out.println("width:"+totalWidth);
        System.out.println("height:"+totalHeight);


        //设置宽度和高度给当前view,通过下面这个方法
        setMeasuredDimension(totalWidth,totalHeight);
    }

    /**
     * 把此view的最终的宽度和高度定下来
     *
     * @param widthMeasureSpec
     * @param heightMeasureSpec
     */



    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {

        int l = 0;
        int t = 0;
        int r = 0;
        int b = 0;
        int childCount = getChildCount();
        for (int i = 0; i <childCount ; i++) {
            //得到每一个view的对象
            final View view = getChildAt(i);
            view.layout(l,t,l+view.getMeasuredWidth(),t + view.getMeasuredHeight());
            l += view.getMeasuredWidth();
            System.out.println("llll:"+l);
            t += view.getMeasuredHeight();
            if(l+view.getMeasuredWidth()>AppUtil.screenWidth(getContext())){
                l = 0;
            }

            //点击事件
            final int finalI = i;
            view.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(getContext(), finalI +":点击位置", Toast.LENGTH_SHORT).show();
                    TextView textView = (TextView) view;
                    Toast.makeText(getContext(), textView.getText().toString() +"文本", Toast.LENGTH_SHORT).show();
                    Intent intent = new Intent(getContext(), MainActivity.class);
                    intent.putExtra("id",textView.getText().toString());
                    getContext().startActivity(intent);
                }
            });
            view.setOnLongClickListener(new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    Toast.makeText(getContext(), finalI +":长按位置", Toast.LENGTH_SHORT).show();
                    removeView(view);
                    return true;
                }
            });
        }
    }
}

  2.ThreeColorActivity(自定义view页面) 
public class ThreeColorActivity extends AppCompatActivity {

    private ThreeColorView threeColorView;
    private int count = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_three_color);
        threeColorView = (ThreeColorView) findViewById(R.id.threecolorview);
    }

    public void add(View view){
        count++;
        int width = AppUtil.screenWidth(this);
        TextView textView = new TextView(this);
        textView.setText(count+"");
        textView.setGravity(Gravity.CENTER);
        textView.setTextColor(getResources().getColor(R.color.white));

        ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(textView, "translationX", (width - width / 3), 0);
        objectAnimator.setDuration(3000);
        objectAnimator.start();
        if(count == 1 || count == 4 || count == 7){
            textView.setBackgroundColor(getResources().getColor(R.color.colorAccent));
        }else {
            textView.setBackgroundColor(getResources().getColor(R.color.colorPrimaryDark));
        }

        threeColorView.addView(textView);

        //得到view的属性参数
        ViewGroup.LayoutParams params = textView.getLayoutParams();
        params.width = width/3;
        params.height = 70;
        textView.setLayoutParams(params);
    }
}
  2.5自定义view对应的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/add"
        android:onClick="add"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <com.example.lenovo.yuekaomoni_0530.view.widget.ThreeColorView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/threecolorview">

    </com.example.lenovo.yuekaomoni_0530.view.widget.ThreeColorView>

</LinearLayout>

 3.  IMainView
public interface IMainView {
    void showGoodsList(UserBean list);
    int getContent();
}

   4.MainActivity (主方法)
public class MainActivity extends AppCompatActivity implements IMainView{

    private int page = 5010;
    private XRecyclerView rv;
    private PresenterImpl presenter;
    private boolean isRefresh = true;//判断是下啦刷新还是上啦加载
    private DbHelper dbHelper;
    private MyAdapter myAdapter;
    private List<UserBean.Data> data;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }

    private void initData() {
        if (getIntent().getExtras() != null) {
            page = 5010 + Integer.parseInt(getIntent().getExtras().getString("id"));
        }

        if (NetWorkUtil.hasWifiConnection(this) || NetWorkUtil.hasGPRSConnection(this)) {
            presenter = new PresenterImpl();
            presenter.showGoodsListToView(new ModelImpl(), this);
        }else {
            Toast.makeText(this, "网络不通畅,请稍后再试!", Toast.LENGTH_SHORT).show();
            String json = null;
//
            //获取数据库对象,可读
            SQLiteDatabase db = dbHelper.getReadableDatabase();
            //获取数据库的游标
            Cursor cursor = db.rawQuery("select * from news", null);
            while (cursor.moveToNext()){
                json = cursor.getString(cursor.getColumnIndex("json"));
            }

            //本地列表刷新
            fillLocalData(json);
        }
    }

    /**
     * 本地列表刷新
     * @param json
     */
    private void fillLocalData(String json) {

        UserBean news = new Gson().fromJson(json,UserBean.class);
        myAdapter = new MyAdapter(data, this,news);
        rv.setAdapter(myAdapter);

    }
    private void initView() {
        rv = (XRecyclerView)findViewById(R.id.xre);
        //设置局部刷新动画
        rv.setItemAnimator(new DefaultItemAnimator());
        //上拉加载
        rv.setLoadingMoreEnabled(true);
        //下拉刷新
        rv.setPullRefreshEnabled(true);
        rv.setLayoutManager(new LinearLayoutManager(this));
        rv.setLoadingListener(new XRecyclerView.LoadingListener() {
            @Override
            public void onRefresh() {

                isRefresh = true;
                //下拉刷新
                page = 5010;
                initData();
            }

            @Override
            public void onLoadMore() {
                isRefresh = false;
                page++;
                initData();
            }
        });

    }


    @Override
    public void showGoodsList(UserBean list) {
        String json = new Gson().toJson(list);
       System.out.println("size:" + list.getData().size());
         data =list.data;
        if(isRefresh) {
            MyAdapter myAdapter = new MyAdapter(data, this,list);
            rv.setAdapter(myAdapter);
           rv.refreshComplete();
            //保存json串数据
//            SQLiteDatabase db = dbHelper.getWritableDatabase();
//            ContentValues contentValues = new ContentValues();
//          contentValues.put("json", json);
//           db.insert(DbHelper.NEWS_TABLE_NAME, null, contentValues);

       }else{
             if(myAdapter != null){
                 myAdapter.loadMore(data);
             }
            rv.loadMoreComplete();
        }
    }

    public int getContent() {
        int s =page;
        return s;
    }
}

  4.5主方法对应的布局
 
< android.support.constraint.ConstraintLayout
xmlns: android = "http://schemas.android.com/apk/res/android" android :layout_width= "match_parent" android :layout_height= "match_parent"> < com.jcodecraeer.xrecyclerview.XRecyclerView android :id= "@+id/xre" android :layout_width= "match_parent" android :layout_height= "wrap_content"> </ com.jcodecraeer.xrecyclerview.XRecyclerView></ android.support.constraint.ConstraintLayout>
   5.MyAdapter (适配器)
public class MyAdapter extends XRecyclerView.Adapter<XRecyclerView.ViewHolder>{

    private List<UserBean.Data> list;
    private Context context;
    private UserBean userBean;

    public MyAdapter(List<UserBean.Data> list, Context context,UserBean userBean) {
        this.list = list;
        this.context = context;
        this.userBean = userBean;
    }

    public void loadMore(List<UserBean.Data> data) {
        if (list != null) {
            list.addAll(data);
            notifyDataSetChanged();
        }
    }

    @Override
    public XRecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType == HttpConfig.TYPE1){
            View view = LayoutInflater.from(context).inflate(R.layout.news_item_layout, parent, false);
            return new Type1ViewHolder(view);
        }else {
            View view = LayoutInflater.from(context).inflate(R.layout.news_item2_layout, parent, false);
            return new Type2ViewHolder(view);
        }
    }

    @Override
    public void onBindViewHolder(final XRecyclerView.ViewHolder holder, int position) {

        //长按删除
        holder.itemView.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public boolean onLongClick(View v) {
               AlertDialog.Builder builder = new  AlertDialog.Builder(context);
                builder.setTitle("删除");
                builder.setNegativeButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //得到下标
                        int pos = holder.getLayoutPosition();
                        System.out.println("pos----"+pos);
                        list.remove(pos);
                       userBean.data  = list;
                        String json =  new Gson().toJson(userBean);
                        notifyDataSetChanged();
                        //notifyItemRemoved(pos);//局部删除当前view并局部刷新
                    }
                });
                builder.setNeutralButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialogInterface, int i) {

                    }
                });
                builder.show();
                return true;
            }
        });


        //多条目加载
        UserBean.Data dataBean = list.get(position);
        if(holder instanceof Type1ViewHolder){
            ((Type1ViewHolder) holder).title.setText(dataBean.getTopic());
            Glide.with(context).load(dataBean.getMiniimg().get(0).getSrc()).into(((Type1ViewHolder) holder).iv1);
        }else if(holder instanceof Type2ViewHolder){
            ((Type2ViewHolder) holder).title.setText(dataBean.getTopic());
            if(dataBean.getMiniimg()!=null&&dataBean.getMiniimg().size()>0){
                  if(dataBean.getMiniimg().size() == 1){
                      Glide.with(context).load(dataBean.getMiniimg().get(0).getSrc()).into(((Type2ViewHolder) holder).iv1);
                      Glide.with(context).load(dataBean.getMiniimg().get(0).getSrc()).into(((Type2ViewHolder) holder).iv2);
                      Glide.with(context).load(dataBean.getMiniimg().get(0).getSrc()).into(((Type2ViewHolder) holder).iv3);
                  }else if (dataBean.getMiniimg().size() == 2){
                      Glide.with(context).load(dataBean.getMiniimg().get(0).getSrc()).into(((Type2ViewHolder) holder).iv1);
                      Glide.with(context).load(dataBean.getMiniimg().get(1).getSrc()).into(((Type2ViewHolder) holder).iv2);
                      Glide.with(context).load(dataBean.getMiniimg().get(1).getSrc()).into(((Type2ViewHolder) holder).iv3);
                  }else{
                      Glide.with(context).load(dataBean.getMiniimg().get(0).getSrc()).into(((Type2ViewHolder) holder).iv1);
                      Glide.with(context).load(dataBean.getMiniimg().get(1).getSrc()).into(((Type2ViewHolder) holder).iv2);
                      Glide.with(context).load(dataBean.getMiniimg().get(2).getSrc()).into(((Type2ViewHolder) holder).iv3);
                  }
            }
        }

    }

    @Override
    public int getItemViewType(int position) {
        return position % 3 ==0? HttpConfig.TYPE1:HttpConfig.TYPE2;
    }

    @Override
    public int getItemCount() {
        return list.size();
    }


    class Type1ViewHolder extends XRecyclerView.ViewHolder{

        private TextView title;
        private ImageView iv1;
        public Type1ViewHolder(View itemView) {
            super(itemView);
            iv1 = (ImageView) itemView.findViewById(R.id.pic1);
            title = (TextView) itemView.findViewById(R.id.title1);
        }
    }

    class Type2ViewHolder extends XRecyclerView.ViewHolder{

        private TextView title;
        private ImageView iv1,iv2,iv3;
        public Type2ViewHolder(View itemView) {
            super(itemView);
            iv1 = (ImageView) itemView.findViewById(R.id.pic_1);
            iv2 = (ImageView) itemView.findViewById(R.id.pic_2);
            iv3 = (ImageView) itemView.findViewById(R.id.pic_3);
            title = (TextView) itemView.findViewById(R.id.title_1);
        }
    }
}

   5.5_1  news_item_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/pic1"
        android:src="@mipmap/ic_launcher"
        android:layout_width="wrap_content"
        android:scaleType="centerCrop"
        android:layout_height="wrap_content"/>


    <LinearLayout
        android:layout_width="0dp"
        android:layout_weight="1"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:layout_marginTop="10dp">

        <TextView
            android:id="@+id/title1"
            android:layout_marginLeft="10dp"
            android:text="我是标题"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>


    </LinearLayout>

</LinearLayout>

   5.5_2  news_item2_layout
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
         android:text="标题"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/title_1"/>
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <ImageView
            android:scaleType="centerCrop"
            android:padding="10dp"
            android:src="@mipmap/ic_launcher"
            android:id="@+id/pic_1"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="50dp" />
        <ImageView
            android:scaleType="centerCrop"
            android:padding="10dp"
            android:src="@mipmap/ic_launcher"
            android:id="@+id/pic_2"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="50dp" />
        <ImageView
            android:scaleType="centerCrop"
            android:padding="10dp"
            android:src="@mipmap/ic_launcher"
            android:id="@+id/pic_3"
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="50dp" />
    </LinearLayout>

</LinearLayout>

七.权限
1.权限
 
< uses-permission android :name= "android.permission.ACCESS_NETWORK_STATE" />< uses-permission android :name= "android.permission.WRITE_EXTERNAL_STORAGE" />< uses-permission android :name= "android.permission.READ_EXTERNAL_STORAGE" />< uses-permission android :name= "android.permission.INTERNET" />< application android :allowBackup= "true" android :supportsRtl= "true" android :theme= "@style/AppTheme"> < activity android :name= ".view.widget.ThreeColorActivity" android :screenOrientation= "portrait"> < intent-filter> < action android :name= "android.intent.action.MAIN" /> < category android :name= "android.intent.category.LAUNCHER" /> </ intent-filter> </ activity> < activity android :name= ".view.MainActivity"></ activity></ application>
  2.
 
compile 'com.google.code.gson:gson:2.6.2'compile 'com.squareup.okhttp3:okhttp:3.3.0'compile 'com.github.bumptech.glide:glide:3.7.0'compile 'com.jcodecraeer:xrecyclerview:1.5.9'
configurations.all {
    resolutionStrategy.eachDependency { DependencyResolveDetails details ->
        def requested = details.requested
        if (requested.group == 'com.android.support') {
            if (!requested.name.startsWith("multidex")) {
                details.useVersion '25.2.0'
            }
        }
    }
}

  3.values下的colors
<color name="white">#FFffff</color>



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值