1. 项目框架:必须使用MVP;
2. 图片加载: Universal-Image-Loader或Glide图片加载框架
3.网络加载框架:OkHttp,二次封装,采用单例模式,自定义应用拦截器,封装公共请求参数(注意:必须通过拦截器封装公共请求参数,否则无法请求数据,判0分)
公共请求参数:source=android
参数名称:source
参数值:android
类型:String
是否必传:是
5. 数据展示使用RecylerView或者XRecyclerView,可以进行下拉刷新和上拉加载更多,下拉刷新的时候请求第一页数据,上拉加载的时候page+1请求更多数据进行展示
6.灵活使用recyclerView的布局管理器,点击右上角图标的时候,图标切换并且展示数据的形式跟随改变,连续再次点击也必须能够改变显示
二.需求
1.图一是搜索页面,实现如图类似布局,中间自定义流式布局,下面是搜索历史,点击搜索后的关键词进行存储,并可以清空历史,,,点击搜索跳转到商品列表页面
2.图二和图三是搜索到商品的列表页面,必须实现下拉刷新和上拉加载更多,自己确定使用什么刷新控件!点击右上角的图标,使用布局管理器进行列表和表格效果的切换
3.对recyclerView的条目添加点击事件,进入图四详情页面,详情页面展示轮播图,标题,价钱,加入购物车,,,点击加入购物车请求购物车接口,吐司加入成功/失败
五、接口:
https://www.zhaoapi.cn/product/searchProducts
keywords=笔记本&page=1
参数说明:
keywords 关键字字段 String类型 必传
page 页码数 String类型 必传
商品详情:
https://www.zhaoapi.cn/product/getProductDetail
参数pid
添加购物车:
https://www.zhaoapi.cn/product/addCart
参数:uid,pid…………uid可以固定传入
公共参数:source 来源字段 String类型 (通过自定义拦截器封装,否则判0分)
来首先我们先添加依赖
compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' compile 'com.google.code.gson:gson:2.8.2' compile 'com.xhb:xbanner:1.2.2' compile 'com.squareup.okhttp3:okhttp:3.6.0' compile 'com.squareup.okio:okio:1.11.0' compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.5' compile 'com.nineoldandroids:library:2.4.0' compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' compile project(':library')这个是PullToRefreshScrollView的依赖
API类
public class API { /* *https://www.zhaoapi.cn/product/searchProducts?keywords=笔记本&page=1&source=android */ public static final String serchpath="https://www.zhaoapi.cn/product/searchProducts"; }
app 类
package com.example.hongliang1510c20171216; import android.app.Application; public class app extends Application { @Override public void onCreate() { super.onCreate(); ImageloaderUtil.init(this); } }
Bean 包
package com.example.hongliang1510c20171216; public class Bean { private String msg; private String code; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } }
ImageloaderUtil 类
package com.example.hongliang1510c20171216; import android.content.Context; import android.graphics.Bitmap; import com.nostra13.universalimageloader.cache.disc.impl.UnlimitedDiskCache; import com.nostra13.universalimageloader.cache.disc.naming.HashCodeFileNameGenerator; import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.ImageLoaderConfiguration; import com.nostra13.universalimageloader.core.assist.ImageScaleType; import com.nostra13.universalimageloader.core.assist.QueueProcessingType; import com.nostra13.universalimageloader.core.display.RoundedBitmapDisplayer; import com.nostra13.universalimageloader.core.download.BaseImageDownloader; import com.nostra13.universalimageloader.utils.StorageUtils; import java.io.File; /** * Created by ML on 2017/12/5. */ public class ImageloaderUtil { public static void init(Context context){ File cacheDir = StorageUtils.getCacheDirectory(context); //缓存文件夹路径 ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(context) .threadPoolSize(3) // default 线程池内加载的数量 .threadPriority(Thread.NORM_PRIORITY - 2) // default 设置当前线程的优先级 .tasksProcessingOrder(QueueProcessingType.FIFO) // default .denyCacheImageMultipleSizesInMemory() .memoryCache(new LruMemoryCache(2 * 1024 * 1024)) //可以通过自己的内存缓存实现 .memoryCacheSize(2 * 1024 * 1024) // 内存缓存的最大值 .memoryCacheSizePercentage(13) // default .diskCache(new UnlimitedDiskCache(cacheDir)) // default 可以自定义缓存路径 .diskCacheSize(50 * 1024 * 1024) // 50 Mb sd卡(本地)缓存的最大值 .diskCacheFileCount(100) // 可以缓存的文件数量 // default为使用HASHCODE对UIL进行加密命名, 还可以用MD5(new Md5FileNameGenerator())加密 .diskCacheFileNameGenerator(new HashCodeFileNameGenerator()) .imageDownloader(new BaseImageDownloader(context)) // default .defaultDisplayImageOptions(DisplayImageOptions.createSimple()) // default .writeDebugLogs() // 打印debug log .build(); //开始构建 ImageLoader.getInstance().init(config); } public static DisplayImageOptions getDefultOption(){ DisplayImageOptions options = new DisplayImageOptions.Builder() .showImageOnLoading(R.mipmap.ic_launcher) // 设置图片下载期间显示的图片 .showImageForEmptyUri(R.mipmap.ic_launcher) // 设置图片Uri为空或是错误的时候显示的图片 .showImageOnFail(R.mipmap.ic_launcher) // 设置图片加载或解码过程中发生错误显示的图片 .resetViewBeforeLoading(true) // default 设置图片在加载前是否重置、复位 .delayBeforeLoading(1000) // 下载前的延迟时间 .cacheInMemory(true) // default 设置下载的图片是否缓存在内存中 .cacheOnDisk(true) // default 设置下载的图片是否缓存在SD卡中 .considerExifParams(true) // default .imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2) // default 设置图片以如何的编码方式显示 .bitmapConfig(Bitmap.Config.ARGB_8888) // default 设置图片的解码类型 .displayer(new RoundedBitmapDisplayer(10)) // default 还可以设置圆角图片new RoundedBitmapDisplayer(20) .build(); return options; } }
Liulayout 类
package com.example.hongliang1510c20171216; import android.content.Context; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; import java.util.ArrayList; import java.util.List; public class Liulayout extends ViewGroup { private List<List<View>> mAllChildViews = new ArrayList<>(); //每一行的高度 private List<Integer> mLineHeight = new ArrayList<>(); public Liulayout(Context context) { this(context, null); // TODO Auto-generated constructor stub } public Liulayout(Context context, AttributeSet attrs) { this(context, attrs, 0); // TODO Auto-generated constructor stub } public Liulayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // TODO Auto-generated constructor stub } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { // TODO Auto-generated method stub //父控件传进来的宽度和高度以及对应的测量模式 int sizeWidth = MeasureSpec.getSize(widthMeasureSpec); int modeWidth = MeasureSpec.getMode(widthMeasureSpec); int sizeHeight = MeasureSpec.getSize(heightMeasureSpec); int modeHeight = MeasureSpec.getMode(heightMeasureSpec); //如果当前ViewGroup的宽高为wrap_content的情况 int width = 0;//自己测量的 宽度 int height = 0;//自己测量的高度 //记录每一行的宽度和高度 int lineWidth = 0; int lineHeight = 0; //获取子view的个数 int childCount = getChildCount(); for(int i = 0;i < childCount; i ++){ View child = getChildAt(i); //测量子View的宽和高 measureChild(child, widthMeasureSpec, heightMeasureSpec); //得到LayoutParams MarginLayoutParams lp = (MarginLayoutParams) getLayoutParams(); //子View占据的宽度 int childWidth = child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; //子View占据的高度 int childHeight = child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin; //换行时候 if(lineWidth + childWidth > sizeWidth){ //对比得到最大的宽度 width = Math.max(width, lineWidth); //重置lineWidth lineWidth = childWidth; //记录行高 height += lineHeight; lineHeight = childHeight; }else{//不换行情况 //叠加行宽 lineWidth += childWidth; //得到最大行高 lineHeight = Math.max(lineHeight, childHeight); } //处理最后一个子View的情况 if(i == childCount -1){ width = Math.max(width, lineWidth); height += lineHeight; } } //wrap_content setMeasuredDimension(modeWidth == MeasureSpec.EXACTLY ? sizeWidth : width, modeHeight == MeasureSpec.EXACTLY ? sizeHeight : height); super.onMeasure(widthMeasureSpec, heightMeasureSpec); } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { // TODO Auto-generated method stub mAllChildViews.clear(); mLineHeight.clear(); //获取当前ViewGroup的宽度 int width = getWidth(); int lineWidth = 0; int lineHeight = 0; //记录当前行的view List<View> lineViews = new ArrayList<View>(); int childCount = getChildCount(); for(int i = 0;i < childCount; i ++){ View child = getChildAt(i); MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int childWidth = child.getMeasuredWidth(); int childHeight = child.getMeasuredHeight(); //如果需要换行 if(childWidth + lineWidth + lp.leftMargin + lp.rightMargin > width){ //记录LineHeight mLineHeight.add(lineHeight); //记录当前行的Views mAllChildViews.add(lineViews); //重置行的宽高 lineWidth = 0; lineHeight = childHeight + lp.topMargin + lp.bottomMargin; //重置view的集合 lineViews = new ArrayList(); } lineWidth += childWidth + lp.leftMargin + lp.rightMargin; lineHeight = Math.max(lineHeight, childHeight + lp.topMargin + lp.bottomMargin); lineViews.add(child); } //处理最后一行 mLineHeight.add(lineHeight); mAllChildViews.add(lineViews); //设置子View的位置 int left = 0; int top = 0; //获取行数 int lineCount = mAllChildViews.size(); for(int i = 0; i < lineCount; i ++){ //当前行的views和高度 lineViews = mAllChildViews.get(i); lineHeight = mLineHeight.get(i); for(int j = 0; j < lineViews.size(); j ++){ View child = lineViews.get(j); //判断是否显示 if(child.getVisibility() == View.GONE){ continue; } MarginLayoutParams lp = (MarginLayoutParams) child.getLayoutParams(); int cLeft = left + lp.leftMargin; int cTop = top + lp.topMargin; int cRight = cLeft + child.getMeasuredWidth(); int cBottom = cTop + child.getMeasuredHeight(); //进行子View进行布局 child.layout(cLeft, cTop, cRight, cBottom); left += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin; } left = 0; top += lineHeight; } } /** * 与当前ViewGroup对应的LayoutParams */ @Override public LayoutParams generateLayoutParams(AttributeSet attrs) { // TODO Auto-generated method stub return new MarginLayoutParams(getContext(), attrs); } }
MainActivity 类
package com.example.hongliang1510c20171216; import android.content.Intent; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; import android.graphics.Color; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.RelativeLayout; import android.widget.TextView; import java.util.ArrayList; import java.util.List; public class MainActivity extends AppCompatActivity implements AdapterView.OnItemClickListener{ private String mNames[] = { "棉裤","大棉袄","大羽绒服", "小羽绒服","北极星挂钟","加湿器", "风信子种球","仙人球防辐射","微波炉" }; private Liulayout liu_layout; private EditText edit_text; private ListView listView; private List<String> list = new ArrayList<>(); private SQLiteDatabase db; private ArrayAdapter<String> stringArrayAdapter; private LinearLayout linear; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); if (getSupportActionBar()!=null){ getSupportActionBar().hide(); } initChildViews(); edit_text = (EditText) findViewById(R.id.edit_text); listView = (ListView) findViewById(R.id.lv); linear = (LinearLayout) findViewById(R.id.linear); linear.setVisibility(View.INVISIBLE); db = openOrCreateDatabase("db", MODE_PRIVATE, null); db.execSQL("create table if not exists user(id integer primary key,name varchar(20))"); Cursor cursor = db.rawQuery("select * from user", null); while (cursor.moveToNext()){ String name = cursor.getString(cursor.getColumnIndex("name")); list.add(name); } if (list.size()>0){ stringArrayAdapter = new ArrayAdapter<>(MainActivity.this, android.R.layout.simple_list_item_1, list); listView.setAdapter(stringArrayAdapter); listView.setOnItemClickListener(this); listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { list.remove(position); stringArrayAdapter.notifyDataSetChanged(); return false; } }); linear.setVisibility(View.VISIBLE); } } private void initChildViews() { // TODO Auto-generated method stub liu_layout = (Liulayout) findViewById(R.id.liu_layout); RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT ,RelativeLayout.LayoutParams.WRAP_CONTENT); lp.leftMargin = 5; lp.rightMargin = 5; lp.topMargin = 5; lp.bottomMargin = 5; for(int i = 0; i < mNames.length; i ++){ TextView view = new TextView(this); view.setText(mNames[i]); view.setTextColor(Color.BLACK); view.setBackgroundDrawable(getResources().getDrawable(R.drawable.textview_bg)); liu_layout.addView(view,lp); } } @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String s = list.get(position); if (s !=null){ Intent intent = new Intent(MainActivity.this,SearchActivity.class); intent.putExtra("str", s); startActivity(intent); } } public void search(View view) { String s = edit_text.getText().toString(); if (s !=null){ Intent intent = new Intent(MainActivity.this,SearchActivity.class); intent.putExtra("str", s); startActivity(intent); db.execSQL("insert into user(name)values(?)",new String[]{s}); list.add(s); stringArrayAdapter.notifyDataSetChanged(); } } }
MyOnItemClickListener 自定义接口
package com.example.hongliang1510c20171216; import android.view.View; public interface MyOnItemClickListener { void OnItemClickListener(View view, int position); }
OkHttp二次封装
package com.example.hongliang1510c20171216; import android.os.Environment; import java.io.File; import java.util.Map; import java.util.concurrent.TimeUnit; import okhttp3.Cache; import okhttp3.Call; import okhttp3.Callback; import okhttp3.FormBody; import okhttp3.OkHttpClient; import okhttp3.Request; public class Okhttputils { public static OkHttpClient okHttpClient=null; public static OkHttpClient getInstance() { if (okHttpClient == null) { synchronized (Okhttputils.class) { if (okHttpClient == null) { File sdcache = new File(Environment.getExternalStorageDirectory(), "regist"); int cacheSize = 10 * 1024 * 1024; okHttpClient = new OkHttpClient.Builder() .connectTimeout(15, TimeUnit.SECONDS) .writeTimeout(20, TimeUnit.SECONDS) .readTimeout(20, TimeUnit.SECONDS) .cache(new Cache(sdcache.getAbsoluteFile(), cacheSize)) .build(); } } } return okHttpClient; } public static void doGet(String url, Callback callback) { OkHttpClient okHttpClient = getInstance(); Request request = new Request.Builder().url(url).build(); Call call = okHttpClient.newCall(request); call.enqueue(callback); } public static void doPost(String url, Map<String, String> params, Callback callback) { OkHttpClient okHttpClient = getInstance(); FormBody.Builder builder = new FormBody.Builder(); for (String key : params.keySet()) { builder.add(key, params.get(key)); } Request request = new Request.Builder().url(url).post(builder.build()).build(); Call call = okHttpClient.newCall(request); call.enqueue(callback); } }
OnItemClickListner 接口
package com.example.hongliang1510c20171216; import android.view.View; public interface OnItemClickListner { public void onItemClick(int position); }
Search_adapter 适配器
package com.example.hongliang1510c20171216; import android.content.Context; import android.content.Intent; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.Toast; import com.nostra13.universalimageloader.core.ImageLoader; import java.util.List; public class Search_adapter extends RecyclerView.Adapter<Searchholder> { Context context; List<SerchBean.DataBean> data; private MyOnItemClickListener itemClickListener; public Search_adapter(Context context, List<SerchBean.DataBean> data) { this.context = context; this.data = data; } @Override public Searchholder onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.search_item_layout,parent,false); Searchholder miaoholder = new Searchholder(view); return miaoholder; } @Override public void onBindViewHolder(final Searchholder holder, final int position) { final String[] split = data.get(position).getImages().split("\\|"); ImageLoader.getInstance().displayImage(split[0],holder.search_img, ImageloaderUtil.getDefultOption()); holder.search_text1.setText(data.get(position).getTitle()); holder.search_text2.setText("¥"+data.get(position).getPrice()+".00"); if (itemClickListener != null) { holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { itemClickListener.OnItemClickListener(holder.itemView, holder.getLayoutPosition()); } }); } } @Override public int getItemCount() { return data.size(); } public void setOnItemClickListener(MyOnItemClickListener itemClickListener) { this.itemClickListener = itemClickListener; } }
Search_adapter_2 适配器2
package com.example.hongliang1510c20171216; import android.content.Context; import android.content.Intent; import android.support.v7.widget.RecyclerView; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import com.nostra13.universalimageloader.core.ImageLoader; import java.util.List; public class Search_adapter_2 extends RecyclerView.Adapter<Searchholder2> { Context context; List<SerchBean.DataBean> data; private MyOnItemClickListener itemClickListener; public Search_adapter_2(Context context, List<SerchBean.DataBean> data) { this.context = context; this.data = data; } @Override public Searchholder2 onCreateViewHolder(ViewGroup parent, int viewType) { View view = LayoutInflater.from(context).inflate(R.layout.search_list_layout,parent,false); Searchholder2 searchholder2 = new Searchholder2(view); return searchholder2; } @Override public void onBindViewHolder(final Searchholder2 holder, int position) { String[] split = data.get(position).getImages().split("\\|"); ImageLoader.getInstance().displayImage(split[0],holder.search_image_view_2, ImageloaderUtil.getDefultOption()); holder.search_text3.setText(data.get(position).getTitle()); holder.search_text4.setText("¥"+data.get(position).getPrice()+".00"); if (itemClickListener != null) { holder.itemView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { itemClickListener.OnItemClickListener(holder.itemView, holder.getLayoutPosition()); } }); } } @Override public int getItemCount() { return data.size(); } public void setOnItemClickListener(MyOnItemClickListener itemClickListener) { this.itemClickListener = itemClickListener; } }
SearchActivity 类
package com.example.hongliang1510c20171216; import android.content.Intent; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.support.v7.widget.GridLayoutManager; import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.OrientationHelper; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.EditText; import android.widget.ImageView; import android.widget.ScrollView; import android.widget.Toast; import com.google.gson.Gson; import com.handmark.pulltorefresh.library.ILoadingLayout; import com.handmark.pulltorefresh.library.PullToRefreshBase; import com.handmark.pulltorefresh.library.PullToRefreshScrollView; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; public class SearchActivity extends AppCompatActivity { private EditText edit_text; private String str; private RecyclerView search_recycler_view; private Search_adapter search_adapter; private ImageView sear_image_view; boolean f =false; private List<SerchBean.DataBean> data = new ArrayList<>(); private Search_adapter_2 search_adapter2; private PullToRefreshScrollView refresh_scroll_view; int page=1; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_search); if (getSupportActionBar()!=null){ getSupportActionBar().hide(); } Intent intent = getIntent(); str = intent.getStringExtra("str"); edit_text = (EditText) findViewById(R.id.edit_text_search); search_recycler_view = (RecyclerView) findViewById(R.id.search_recycler_view); sear_image_view = (ImageView) findViewById(R.id.search_image_view); refresh_scroll_view = (PullToRefreshScrollView) findViewById(R.id.refresh_scroll_view); refresh(); edit_text.setText(str); getdata(str); } private void refresh() { refresh_scroll_view.setMode(PullToRefreshBase.Mode.BOTH); ILoadingLayout startLabels = refresh_scroll_view .getLoadingLayoutProxy(true, false); startLabels.setPullLabel("下拉刷新"); startLabels.setRefreshingLabel("正在拉"); startLabels.setReleaseLabel("放开刷新"); ILoadingLayout endLabels = refresh_scroll_view.getLoadingLayoutProxy( false, true); endLabels.setPullLabel("上拉刷新"); endLabels.setRefreshingLabel("正在载入..."); endLabels.setReleaseLabel("放开刷新..."); refresh_scroll_view.setOnRefreshListener(new PullToRefreshBase.OnRefreshListener2<ScrollView>() { @Override public void onPullDownToRefresh(PullToRefreshBase<ScrollView> refreshView) { getdata(str); } @Override public void onPullUpToRefresh(PullToRefreshBase<ScrollView> refreshView) { page++; getdata(str); } }); } private void getdata(String str) { Map<String, String> params = new HashMap<>(); params.put("keywords", str); params.put("page",page+""); params.put("source","android"); Okhttputils.doPost(API.serchpath, params, new Callback() { @Override public void onFailure(Call call, IOException e) { e.printStackTrace(); } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ final String string = response.body().string(); if (string!=null){ runOnUiThread(new Runnable() { @Override public void run() { SerchBean serchBean = new Gson().fromJson(string, SerchBean.class); data.addAll(serchBean.getData()) ; search_recycler_view.setLayoutManager(new GridLayoutManager(SearchActivity.this,2, OrientationHelper.VERTICAL,false)); search_adapter = new Search_adapter(SearchActivity.this, data); search_recycler_view.setAdapter(search_adapter); refresh_scroll_view.onRefreshComplete(); search_adapter.setOnItemClickListener(new MyOnItemClickListener() { @Override public void OnItemClickListener(View view, int position) { Intent intent =new Intent(SearchActivity.this,XiangqingActivity.class); intent.putExtra("imgs",data.get(position).getImages()); intent.putExtra("title",data.get(position).getTitle()); intent.putExtra("yuan",data.get(position).getPrice()+""); intent.putExtra("xian",data.get(position).getPscid()+""); intent.putExtra("pid",data.get(position).getPid()+""); startActivity(intent); } }); } }); } } } }); } public void search(View view) { if (f){ f=false; sear_image_view.setImageResource(R.drawable.kind_grid); search_recycler_view.setLayoutManager(new LinearLayoutManager(SearchActivity.this,LinearLayoutManager.VERTICAL,false)); search_adapter2 = new Search_adapter_2(SearchActivity.this, data); search_recycler_view.setAdapter(search_adapter2); search_adapter2.setOnItemClickListener(new MyOnItemClickListener() { @Override public void OnItemClickListener(View view, int position) { Intent intent =new Intent(SearchActivity.this,XiangqingActivity.class); intent.putExtra("imgs",data.get(position).getImages()); intent.putExtra("title",data.get(position).getTitle()); intent.putExtra("yuan",data.get(position).getPrice()+""); intent.putExtra("xian",data.get(position).getPscid()+""); intent.putExtra("pid",data.get(position).getPid()+""); startActivity(intent); } }); }else { f=true; sear_image_view.setImageResource(R.drawable.kind_liner); search_recycler_view.setLayoutManager(new GridLayoutManager(SearchActivity.this,2, OrientationHelper.VERTICAL,false)); search_adapter = new Search_adapter(SearchActivity.this, data); search_recycler_view.setAdapter(search_adapter); search_adapter.setOnItemClickListener(new MyOnItemClickListener() { @Override public void OnItemClickListener(View view, int position) { Intent intent =new Intent(SearchActivity.this,XiangqingActivity.class); intent.putExtra("imgs",data.get(position).getImages()); intent.putExtra("title",data.get(position).getTitle()); intent.putExtra("yuan",data.get(position).getPrice()+""); intent.putExtra("xian",data.get(position).getPscid()+""); intent.putExtra("pid",data.get(position).getPid()+""); startActivity(intent); } }); } } public void fan_hui(View view) { Intent intent = new Intent(SearchActivity.this,MainActivity.class); startActivity(intent); } }
Searchholder 类
package com.example.hongliang1510c20171216; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageView; import android.widget.TextView; public class Searchholder extends RecyclerView.ViewHolder { public ImageView search_img; public TextView search_text1; public TextView search_text2; public Searchholder(View itemView) { super(itemView); search_img = (ImageView) itemView.findViewById(R.id.search_img); search_text1 = (TextView) itemView.findViewById(R.id.search_text1); search_text2 = (TextView) itemView.findViewById(R.id.search_text2); } }
Searchholder2 类
package com.example.hongliang1510c20171216; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageView; import android.widget.TextView; public class Searchholder2 extends RecyclerView.ViewHolder { public ImageView search_image_view_2; public TextView search_text3; public TextView search_text4; public Searchholder2(View itemView) { super(itemView); search_image_view_2 = (ImageView) itemView.findViewById(R.id.search_image_view_2); search_text3 = (TextView) itemView.findViewById(R.id.search_text3); search_text4 = (TextView) itemView.findViewById(R.id.search_text4); } }
SerchBean 类
package com.example.hongliang1510c20171216; import java.io.Serializable; import java.util.List; public class SerchBean implements Serializable{ /** * msg : 查询成功 * code : 0 * data : [{"bargainPrice":11800,"createtime":"2017-10-10T17:33:37","detailUrl":"https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg","itemtype":0,"pid":57,"price":5199,"pscid":40,"salenum":4343,"sellerid":1,"subhead":"【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统","title":"小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银\r\n"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://item.m.jd.com/product/5025518.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n0/jfs/t8830/106/1760940277/195595/5cf9412f/59bf2ef5N5ab7dc16.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5428/70/1520969931/274676/b644dd0d/591128e7Nd2f70da0.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5566/365/1519564203/36911/620c750c/591128eaN54ac3363.jpg!q70.jpg","itemtype":1,"pid":58,"price":6399,"pscid":40,"salenum":545,"sellerid":2,"subhead":"升级4G大显存!Nvme协议Pcie SSD,速度快人一步】GTX1050Ti就选拯救者!专业游戏键盘&新模具全新设计!","title":"联想(Lenovo)拯救者R720 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 1T+128G SSD GTX1050Ti 4G IPS 黑)"},{"bargainPrice":5599,"createtime":"2017-10-10T17:30:32","detailUrl":"https://item.m.jd.com/product/4824715.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends","images":"https://m.360buyimg.com/n12/jfs/t7768/184/1153704394/148460/f42e1432/599a930fN8a85626b.jpg!q70.jpg","itemtype":0,"pid":59,"price":5599,"pscid":40,"salenum":675,"sellerid":3,"subhead":"游戏本选择4G独显,拒绝掉帧】升级版IPS全高清防眩光显示屏,WASD方向键颜色加持,三大出风口立体散热!","title":"戴尔DELL灵越游匣15PR-6648B GTX1050 15.6英寸游戏笔记本电脑(i5-7300HQ 8G 128GSSD+1T 4G独显 IPS)黑"},{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":2,"pid":60,"price":13888,"pscid":40,"salenum":466,"sellerid":4,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":1,"pid":61,"price":14999,"pscid":40,"salenum":5535,"sellerid":5,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-03T23:53:28","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":0,"pid":62,"price":15999,"pscid":40,"salenum":43,"sellerid":6,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":1,"pid":63,"price":10000,"pscid":40,"salenum":3232,"sellerid":7,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-03T23:43:53","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":0,"pid":64,"price":11000,"pscid":40,"salenum":0,"sellerid":8,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-14T21:48:08","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":2,"pid":65,"price":12000,"pscid":40,"salenum":868,"sellerid":9,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"},{"bargainPrice":11800,"createtime":"2017-10-14T21:38:26","detailUrl":"https://mitem.jd.hk/ware/view.action?wareId=1988853309&cachekey=1acb07a701ece8d2434a6ae7fa6870a1","images":"https://m.360buyimg.com/n0/jfs/t6130/97/1370670410/180682/1109582a/593276b1Nd81fe723.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5698/110/2617517836/202970/c9388feb/593276b7Nbd94ef1f.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5815/178/2614671118/51656/7f52d137/593276c7N107b725a.jpg!q70.jpg|https://m.360buyimg.com/n0/jfs/t5878/60/2557817477/30873/4502b606/593276caN5a7d6357.jpg!q70.jpg","itemtype":1,"pid":66,"price":13000,"pscid":40,"salenum":7676,"sellerid":10,"subhead":"购买电脑办公部分商品满1元返火车票5元优惠券(返完即止)","title":"全球购 新款Apple MacBook Pro 苹果笔记本电脑 银色VP2新13英寸Bar i5/8G/256G"}] * page : 1 */ private String msg; private String code; private String page; private List<DataBean> data; public String getMsg() { return msg; } public void setMsg(String msg) { this.msg = msg; } public String getCode() { return code; } public void setCode(String code) { this.code = code; } public String getPage() { return page; } public void setPage(String page) { this.page = page; } public List<DataBean> getData() { return data; } public void setData(List<DataBean> data) { this.data = data; } public static class DataBean implements Serializable{ /** * bargainPrice : 11800.0 * createtime : 2017-10-10T17:33:37 * detailUrl : https://item.m.jd.com/product/4338107.html?utm#_source=androidapp&utm#_medium=appshare&utm#_campaign=t#_335139774&utm#_term=QQfriends * images : https://m.360buyimg.com/n0/jfs/t6700/155/2098998076/156185/6cf95035/595dd5a5Nc3a7dab5.jpg!q70.jpg * itemtype : 0 * pid : 57 * price : 5199.0 * pscid : 40 * salenum : 4343 * sellerid : 1 * subhead : 【i5 MX150 2G显存】全高清窄边框 8G内存 256固态硬盘 支持指纹识别 预装WIN10系统 * title : 小米(MI)Air 13.3英寸全金属轻薄笔记本(i5-7200U 8G 256G PCle SSD MX150 2G独显 FHD 指纹识别 Win10)银 */ private double bargainPrice; private String createtime; private String detailUrl; private String images; private int itemtype; private int pid; private double price; private int pscid; private int salenum; private int sellerid; private String subhead; private String title; public double getBargainPrice() { return bargainPrice; } public void setBargainPrice(double bargainPrice) { this.bargainPrice = bargainPrice; } public String getCreatetime() { return createtime; } public void setCreatetime(String createtime) { this.createtime = createtime; } public String getDetailUrl() { return detailUrl; } public void setDetailUrl(String detailUrl) { this.detailUrl = detailUrl; } public String getImages() { return images; } public void setImages(String images) { this.images = images; } public int getItemtype() { return itemtype; } public void setItemtype(int itemtype) { this.itemtype = itemtype; } public int getPid() { return pid; } public void setPid(int pid) { this.pid = pid; } public double getPrice() { return price; } public void setPrice(double price) { this.price = price; } public int getPscid() { return pscid; } public void setPscid(int pscid) { this.pscid = pscid; } public int getSalenum() { return salenum; } public void setSalenum(int salenum) { this.salenum = salenum; } public int getSellerid() { return sellerid; } public void setSellerid(int sellerid) { this.sellerid = sellerid; } public String getSubhead() { return subhead; } public void setSubhead(String subhead) { this.subhead = subhead; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } } }
XiangqingActivity 类
package com.example.hongliang1510c20171216; import android.content.Intent; import android.graphics.Paint; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.TextView; import android.widget.Toast; import com.google.gson.Gson; import com.nostra13.universalimageloader.core.ImageLoader; import com.stx.xhb.xbanner.XBanner; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import okhttp3.Call; import okhttp3.Callback; import okhttp3.Response; public class XiangqingActivity extends AppCompatActivity implements View.OnClickListener { private XBanner banner; private TextView t1; private TextView t2; private TextView t3; private String pid; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_xiangqing); Intent intent = getIntent(); String imgs = intent.getStringExtra("imgs"); String title = intent.getStringExtra("title"); String yuan = intent.getStringExtra("yuan"); String xian = intent.getStringExtra("xian"); pid = intent.getStringExtra("pid"); String[] split = imgs.split("\\|"); final List<String>list = new ArrayList<>(); banner = (XBanner) findViewById(R.id.banner); t1 = (TextView) findViewById(R.id.t1); t2 = (TextView) findViewById(R.id.t2); t3 = (TextView) findViewById(R.id.t3); TextView fanhui = (TextView) findViewById(R.id.fanhui); fanhui.setOnClickListener(this); for (int i=0;i<split.length;i++){ list.add(split[i]); } banner.setData(list,null); banner.setmAdapter(new XBanner.XBannerAdapter() { @Override public void loadBanner(XBanner banner, View view, int position) { ImageLoader.getInstance().displayImage(list.get(position), (ImageView) view,ImageloaderUtil.getDefultOption()); } }); t1.setText(title); t2.setText("原价:"+yuan); t2.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG ); t3.setText("优惠价:"+xian); } public void add(View view) { Map<String, String> params = new HashMap<>(); params.put("uid","2792"); params.put("pid",pid); Okhttputils.doPost("https://www.zhaoapi.cn/product/addCart?source=android", params, new Callback() { @Override public void onFailure(Call call, IOException e) { e.printStackTrace(); } @Override public void onResponse(Call call, Response response) throws IOException { if (response.isSuccessful()){ final String string = response.body().string(); runOnUiThread(new Runnable() { @Override public void run() { if (string!=null){ Bean bean = new Gson().fromJson(string, Bean.class); String code = bean.getCode(); if ("0".equals(code)){ Toast.makeText(XiangqingActivity.this,bean.getMsg(),Toast.LENGTH_SHORT).show(); } } } }); } } }); } @Override public void onClick(View v) { XiangqingActivity.this.finish(); } }
sha2
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="10dp"/>
<solid android:color="#F3F4F5"/>
<size android:height="10dp" android:width="600dp"/>
</shape>
textview_bg
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#F3F4F5" />
<corners android:radius="10dp" />
<padding
android:left="5dp"
android:right="5dp"
android:top="5dp"
android:bottom="5dp"
/>
</shape>
布局文件
activity
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.hongliang1510c20171216.MainActivity"> <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" > <ImageView android:onClick="fan" android:src="@drawable/leftjiantou" android:layout_width="25dp" android:layout_height="25dp" android:layout_marginTop="10dp" android:layout_marginLeft="15dp" /> <EditText android:id="@+id/edit_text" android:hint="好货来袭,抢海量尖货" android:layout_marginLeft="10dp" android:background="@drawable/sha2" android:layout_width="360dp" android:layout_height="30dp" /> <Button android:onClick="search" android:background="#fff" android:text="搜索" android:layout_width="50dp" android:layout_height="50dp" android:layout_marginLeft="10dp" /> </LinearLayout> <TextView android:background="#F3F4F5" android:layout_width="match_parent" android:layout_height="5dp" /> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:text="热搜" android:textColor="#000" android:textSize="20sp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <com.example.hongliang1510c20171216.Liulayout android:id="@+id/liu_layout" android:layout_width="match_parent" android:layout_height="100dp"></com.example.hongliang1510c20171216.Liulayout> </LinearLayout> <TextView android:background="#F3F4F5" android:layout_width="match_parent" android:layout_height="10dp" /> <LinearLayout android:id="@+id/linear" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:text="历史搜索" android:textColor="#000" android:textSize="20sp" android:layout_width="match_parent" android:layout_height="30dp" /> <ListView android:id="@+id/lv" android:layout_width="match_parent" android:layout_height="wrap_content"></ListView> <Button android:onClick="clear" android:layout_gravity="center" android:text="清空历史搜索" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
activity_search
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:ptr="http://schemas.android.com/apk/res-auto" 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" android:orientation="vertical" tools:context="com.example.hongliang1510c20171216.SearchActivity"> <com.handmark.pulltorefresh.library.PullToRefreshScrollView android:layout_height="match_parent" android:layout_width="match_parent" android:id="@+id/refresh_scroll_view" ptr:ptrDrawable="@drawable/default_ptr_flip" ptr:ptrAnimationStyle="flip" ptr:ptrHeaderBackground="#383838" ptr:ptrHeaderTextColor="#FFFFFF"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="50dp" android:orientation="horizontal" > <ImageView android:onClick="fan_hui" android:src="@drawable/leftjiantou" android:layout_width="25dp" android:layout_height="25dp" android:layout_marginTop="10dp" android:layout_marginLeft="15dp" /> <EditText android:selectAllOnFocus="false" android:id="@+id/edit_text_search" android:layout_marginLeft="10dp" android:layout_marginTop="8dp" android:background="@drawable/sha2" android:layout_width="360dp" android:layout_height="30dp" /> <ImageView android:id="@+id/search_image_view" android:onClick="search" android:layout_marginTop="8dp" android:src="@drawable/kind_liner" android:layout_width="30dp" android:layout_height="30dp" android:layout_marginLeft="10dp" /> </LinearLayout> <TextView android:background="#F3F4F5" android:layout_width="match_parent" android:layout_height="5dp" /> <android.support.v7.widget.RecyclerView android:id="@+id/search_recycler_view" android:layout_width="match_parent" android:layout_height="match_parent"></android.support.v7.widget.RecyclerView> </LinearLayout> </com.handmark.pulltorefresh.library.PullToRefreshScrollView> </LinearLayout>
activity_xiangqing
<?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" android:orientation="vertical" tools:context="com.example.hongliang1510c20171216.XiangqingActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:id="@+id/fanhui" android:text="<" android:textSize="30sp" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:text="商品详情" android:textSize="30sp" android:layout_centerHorizontal="true" android:layout_centerVertical="true" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RelativeLayout> <com.stx.xhb.xbanner.XBanner android:id="@+id/banner" android:layout_width="match_parent" android:layout_height="400dp" app:AutoPlayTime="2000" app:pointsContainerBackground="#44AAAAAA" app:pointsPosition="CENTER" app:tipTextColor="#FFFFFFFF" app:tipTextSize="16.0sp" /> <TextView android:id="@+id/t1" android:layout_marginTop="10dp" android:textSize="25sp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/t2" android:layout_marginTop="10dp" android:textSize="25sp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:id="@+id/t3" android:textColor="#f00" android:layout_marginTop="10dp" android:textSize="25sp" android:layout_width="match_parent" android:layout_height="wrap_content" /> <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:onClick="add" android:text="加入购物车" android:background="#f00" android:textColor="#fff" android:layout_alignParentBottom="true" android:layout_width="match_parent" android:layout_height="wrap_content" /> </RelativeLayout> </LinearLayout>
search_item_layout
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:id="@+id/search_img" android:layout_width="match_parent" android:layout_height="200dp" /> <TextView android:id="@+id/search_text1" android:layout_width="match_parent" android:layout_height="wrap_content" /> <TextView android:textColor="#f00" android:id="@+id/search_text2" android:layout_width="match_parent" android:layout_height="wrap_content" /> </LinearLayout>
search_list_layout
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/search_image_view_2" android:layout_width="200dp" android:layout_height="200dp" /> <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="100dp"> <TextView android:id="@+id/search_text3" android:layout_width="match_parent" android:layout_height="70dp" /> <TextView android:id="@+id/search_text4" android:textColor="#f00" android:layout_width="match_parent" android:layout_height="30dp" /> </LinearLayout> </LinearLayout>
配置文件
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.hongliang1510c20171216"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <application android:name=".app" android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".SearchActivity" /> <activity android:name=".XiangqingActivity"></activity> </application> </manifest>