多条目展示+WebView

recycleView布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
<TextView
    android:id="@+id/mlss_name"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="40sp"
    android:textStyle="bold"
    android:gravity="center"
    />
    <android.support.v7.widget.RecyclerView
        android:id="@+id/mlss_recycler"
        android:layout_width="match_parent"
        android:layout_margin="10dp"
        android:layout_height="wrap_content"></android.support.v7.widget.RecyclerView>
</LinearLayout>

适配器布局

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    android:padding="10dp"
    app:cardCornerRadius="10dp"
    app:cardElevation="10dp"
    >
<LinearLayout
    android:layout_width="wrap_content"
    android:orientation="vertical"
    android:gravity="center"
    android:layout_height="wrap_content"
    >
    <com.facebook.drawee.view.SimpleDraweeView
        android:id="@+id/mlss_item_img"
        android:layout_width="200dp"
        android:layout_height="250dp"
        />
    <TextView
        android:id="@+id/mlss_item_name"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxWidth="200dp"
        android:maxLines="1"
        android:textSize="20sp"
        />
</LinearLayout>
</android.support.v7.widget.CardView>

最大recycleView

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    >
<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    >
    <com.stx.xhb.xbanner.XBanner
        android:id="@+id/xbanner"
        android:layout_width="match_parent"
        android:layout_height="250dp"
        android:isScrollContainer="true"
        ></com.stx.xhb.xbanner.XBanner>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/home_recy_rxxp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/home_recy_pzsh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
    <android.support.v7.widget.RecyclerView
        android:id="@+id/home_recy_mlss"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></android.support.v7.widget.RecyclerView>
</LinearLayout>
</ScrollView>
</LinearLayout>

recycleView图片切割

public class HomeMlssRecyclerAdapater extends BaseMultiItemQuickAdapter<HomeBean.ResultBean.MlssBean.CommodityListBeanXX,BaseViewHolder> {


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public HomeMlssRecyclerAdapater(List<HomeBean.ResultBean.MlssBean.CommodityListBeanXX> data) {
        super(data);
        addItemType(0, R.layout.item_mlss_item);

    }

    @Override
    protected void convert(BaseViewHolder helper, HomeBean.ResultBean.MlssBean.CommodityListBeanXX item) {
        helper.setText(R.id.mlss_item_name,item.getCommodityName());
        SimpleDraweeView mlss_item_img = helper.getView(R.id.mlss_item_img);
        mlss_item_img.setImageURI(item.getMasterPic());
    }
}

recycleView适配器

public class HomeMlssItemRecyclerViewAdapater extends BaseMultiItemQuickAdapter<HomeBean.ResultBean.MlssBean,BaseViewHolder> {

    private RecyclerView mlss_recycler;
    private HomeMlssRecyclerAdapater mlssRecyclerAdapater;


    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public HomeMlssItemRecyclerViewAdapater(List<HomeBean.ResultBean.MlssBean> data) {
        super(data);
        addItemType(0, R.layout.item_mlss);

    }


    @Override
    protected void convert(BaseViewHolder helper, HomeBean.ResultBean.MlssBean item) {
        helper.setText(R.id.mlss_name,item.getName());
        mlss_recycler = helper.getView(R.id.mlss_recycler);
        mlss_recycler.setLayoutManager(new StaggeredGridLayoutManager(2,0));
        mlssRecyclerAdapater = new HomeMlssRecyclerAdapater(item.getCommodityList());
        mlss_recycler.setAdapter(this.mlssRecyclerAdapater);
    }
}

多条目展示

public class TabHomePage extends BaseFragment<BannerContract.BannView, BannerPersenter<BannerContract.BannView>> implements BannerContract.BannView {
    @BindView(R.id.xbanner)
    XBanner xbanner;
    @BindView(R.id.home_recy_rxxp)
    RecyclerView homeRecyRxxp;
    Unbinder unbinder;
    @BindView(R.id.home_recy_pzsh)
    RecyclerView homeRecyPzsh;
    @BindView(R.id.home_recy_mlss)
    RecyclerView homeRecyMlss;


    @Override
    protected void initData() {
        persenter.getData(getActivity());
    }

    @Override
    protected BannerPersenter<BannerContract.BannView> CreatePersenter() {
        return new BannerPersenter<>();
    }

    @Override
    protected int getLayout() {
        return R.layout.tab_homepage;
    }


    @Override
    public void Bannyoyo(final BannerBean bannerBean) {
        xbanner.setBannerData(bannerBean.getResult());
        xbanner.loadImage(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                xbanner.startAutoPlay();
                Glide.with(getContext()).load(bannerBean.getResult().get(position).getXBannerUrl()).into((ImageView) view);
            }
        });
        xbanner.setAutoPalyTime(2000);
        xbanner.stopAutoPlay();
        xbanner.setOnItemClickListener(new XBanner.OnItemClickListener() {
            @Override
            public void onItemClick(XBanner banner, Object model, View view, int position) {
                if (position==2){
                    Intent intent = new Intent(getActivity(), WebActivity.class);
                    getActivity().startActivity(intent);
                }

            }
        });
    }

    @Override
    public void Homeyoyo(HomeBean homeBean) {
        // TODO: 2019/10/25  热销新品
        List<HomeBean.ResultBean.RxxpBean> rxxpBeans = new ArrayList<>();
        rxxpBeans.add(homeBean.getResult().getRxxp());
        homeRecyRxxp.setLayoutManager(new LinearLayoutManager(getActivity()));
        homeRecyRxxp.setAdapter(new HomeRxxpItemRecyclerAdapater(rxxpBeans));
        // TODO: 2019/10/25  魔丽时尚
        List<HomeBean.ResultBean.MlssBean>mlssBeans=new ArrayList<>();
        mlssBeans.add(homeBean.getResult().getMlss());
        homeRecyMlss.setLayoutManager(new LinearLayoutManager(getActivity()));
        homeRecyMlss.setAdapter(new HomeMlssItemRecyclerViewAdapater(mlssBeans));
        // TODO: 2019/10/25  品质生活
        List<HomeBean.ResultBean.PzshBean> pzshBeans = new ArrayList<>();
        pzshBeans.add(homeBean.getResult().getPzsh());
        homeRecyPzsh.setLayoutManager(new LinearLayoutManager(getActivity()));
        homeRecyPzsh.setAdapter(new HomePzshItemRecyclerViewAdapater(pzshBeans));
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}

webview展示

public class WebActivity extends AppCompatActivity {

    private WebView webview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_web);
        webview = findViewById(R.id.webview);
        // TODO: 2019/10/28 获取设置
        WebSettings settings = webview.getSettings();
        // TODO: 2019/10/28 设置支持js
        settings.setJavaScriptEnabled(true);
        // TODO: 2019/10/28  加载本地文件
        webview.loadUrl("file:///android_asset/login.html");
        // TODO: 2019/10/28 支持alert//返回false是支持
        webview.setWebChromeClient(new WebChromeClient(){
            @Override
            public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
                return false;
            }
        });
        webview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                webview.loadUrl("javascript:login()");
            }
        });
        //js支持调用安卓的方法 //添加支持调用
        webview.addJavascriptInterface(this,"android");
    }
    //添加注解
    @JavascriptInterface
    public void json(String name,String pwd){
        Toast.makeText(this, ""+name+pwd, Toast.LENGTH_SHORT).show();
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值