布局 使用 三个RecyclerView
布局================================xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone"
android:id="@+id/FrameLayout_id"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<bawei.com.zhaolingling_moni_20190530.MySsView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mySerchView"/>
<com.stx.xhb.xbanner.XBanner
app:AutoPlayTime="1000"
app:pointsVisibility="false"
app:isClipChildrenMode="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:layout_width="match_parent"
android:layout_height="163dp"
android:id="@+id/ban"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
ndroid:layout_marginTop="20dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@mipmap/rxxp"
android:text="热销新品"
android:textSize="16sp"
android:textColor="#ff7f57"
android:gravity="center"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rxxplist"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp" >
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="20dp" >
<TextView
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@mipmap/mlss"
android:text="魔力时尚"
android:textSize="16sp"
android:textColor="#3258ef"
android:gravity="center"
/>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/mlsslist"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginTop="10dp"
>
<TextView
android:layout_width="match_parent"
android:layout_height="30dp"
android:background="@mipmap/pzsh"
android:text="品质生活"
android:textSize="16sp"
android:textColor="#ff038d"
android:gravity="center"
/>
<android.support.v7.widget.RecyclerView
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/pzshlist"
android:layout_marginTop="10dp"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
//适配器=================
public class SyAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
private List<SyBean.Itme> mlist;
private Context context;
private String name;
public SyAdapter(Context context, String name, List<SyBean.Itme> mlist) {
this.mlist = mlist;
this.context = context;
this.name = name;
}
@NonNull
@Override
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
switch (i) {
case 0:
return new RxxpHolder(View.inflate(context, R.layout.rxxp_itme, null));
case 1:
return new MlssHolder(View.inflate(context, R.layout.mlss_itme, null));
case 2:
return new PzshHolder(View.inflate(context, R.layout.pzsh, null));
}
return null;
}
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
AdeHoidelView adeHoidelView = (AdeHoidelView) viewHolder;
adeHoidelView.BindViewHolder(mlist, context, i);
}
@Override
public int getItemCount() {
return mlist.size();
}
@Override
public int getItemViewType(int position) {
if (name.equals("热销新品")) {
return 0;
} else if (name.equals("魔力时尚")) {
return 1;
} else {
return 2;
}
}
//总的RecyclerView
public abstract class AdeHoidelView extends RecyclerView.ViewHolder {
public AdeHoidelView(@NonNull View itemView) {
super(itemView);
}
public abstract void BindViewHolder(List<SyBean.Itme> mlist, Context context, int i);
}
、、//三个条目的 继承 AdeHoidelView
public class MlssHolder extends AdeHoidelView {
private final ImageView mlss_img;
private final TextView mlss_title,mlss_price;
public MlssHolder(@NonNull View itemView) {
super(itemView);
mlss_img = itemView.findViewById(R.id.mlss_img);
mlss_title = itemView.findViewById(R.id.mlss_title);
mlss_price = itemView.findViewById(R.id.mlss_price);
}
@Override
public void BindViewHolder(List<SyBean.Itme> mlist, Context context, int i) {
Glide.with(context).load(mlist.get(i).masterPic).into(mlss_img);
mlss_title.setText(mlist.get(i).commodityName);
mlss_price.setText("¥"+String.valueOf(mlist.get(i).price));
}
//activity实现//显示列表
private class setSy implements DataCall {
private SyAdapter rxxpAdpater;
private SyAdapter mlssAdpater;
private SyAdapter pzshAdpater;
@Override
public void suesser(Object o) {
Result<SyBean> goodsBean = (Result<SyBean>) o;
final SyBean result = goodsBean.getResult();
rxxpAdpater = new SyAdapter(MainActivity.this, result.rxxp.name, result.rxxp.commodityList);
mlssAdpater = new SyAdapter(MainActivity.this, result.mlss.name, result.mlss.commodityList);
pzshAdpater = new SyAdapter(MainActivity.this, result.pzsh.name, result.pzsh.commodityList);
rxxplist.setAdapter(rxxpAdpater);
mlsslist.setAdapter(mlssAdpater);
pzshlist.setAdapter(pzshAdpater);
}
@Override
public void fnil(String mag) {
Toast.makeText(MainActivity.this, "列表展示失败", Toast.LENGTH_SHORT).show();
}}