1.依赖

implementation \'com.squareup.okhttp3:okhttp:3.12.0\'
    implementation \'com.android.support:recyclerview-v7:28.0.0\'
    implementation \'com.google.code.gson:gson:2.8.5\'
    implementation \'com.android.support:recyclerview-v7:28.0.0\'
    implementation(\'com.jcodecraeer:xrecyclerview:1.5.9\') {
        exclude group: \'com.android.support\'
    }
    implementation \'com.github.bumptech.glide:glide:4.8.0\'

2.权限

<uses-permission android:name=\"android.permission.INTERNET\" />
    <!-- 必须的权限 -->
    <uses-permission android:name=\"android.permission.ACCESS_NETWORK_STATE\" />
    <uses-permission android:name=\"android.permission.ACCESS_WIFI_STATE\" />
    <uses-permission android:name=\"android.permission.READ_PHONE_STATE\" />
    <uses-permission android:name=\"android.permission.WRITE_EXTERNAL_STORAGE\" />
    <uses-permission android:name=\"android.permission.READ_EXTERNAL_STORAGE\" />

3.MainActivity

package com.example.lenovo.dsweek03;

import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.PopupWindow;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.example.lenovo.dsweek03.adapter.MyAdapter;
import com.example.lenovo.dsweek03.adapter.XRecyclerViewAdapter;
import com.example.lenovo.dsweek03.adapter.XRecyclerViewAdapter2;
import com.example.lenovo.dsweek03.bean.Goods;
import com.example.lenovo.dsweek03.bean.Result;
import com.example.lenovo.dsweek03.core.DataCall;
import com.example.lenovo.dsweek03.core.Item a;
import com.example.lenovo.dsweek03.presenter.GoodsPresenter;
import com.jcodecraeer.xrecyclerview.XRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity implements View. Listener,DataCall<List<Goods>>, XRecyclerView.LoadingListener {
    private Button login;
    private XRecyclerView xrecyclerView;
    private GoodsPresenter goodsPresenter;
    List<Goods> list=new ArrayList<>();
    private XRecyclerViewAdapter xRecyclerViewAdapter;
    private XRecyclerViewAdapter2 xRecyclerViewAdapter2;
    int page=1;
    private ImageButton btn_show;
    private PopupWindow window;
    private ImageButton list_pop;
    private ImageButton grid_pop;
    private XRecyclerView list_view;
    private MyAdapter myAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
//        login = findViewById(R.id.login);
        xrecyclerView = (XRecyclerView) findViewById(R.id.xrecyclerView);

        /**
         *
         * mvp实现数据
         */
        goodsPresenter = new GoodsPresenter(this);
//        goodsPresenter.requestData(true);
        /**
         * xrecyclerView + 上拉下载
         */
        //多条目加载点击更多
        xrecyclerView.setLoadingListener(this);
        //瀑布流
        // 第一个参数是 一共显示两行、第二个是布局竖向排列
        StaggeredGridLayoutManager staggeredGridLayoutManager = new StaggeredGridLayoutManager(2,StaggeredGridLayoutManager.VERTICAL);
        //设置管理
        xrecyclerView.setLayoutManager(staggeredGridLayoutManager);
        //设置适配器
        xRecyclerViewAdapter2 = new XRecyclerViewAdapter2(this,list);
        xrecyclerView.setAdapter(xRecyclerViewAdapter2);
        //加载数据(刷新)
        xrecyclerView.refresh();
        //找控件
        btn_show =  findViewById(R.id.btn_show);
        list_view = findViewById(R.id.list_view);
        //单条目加载点击更多
        list_view.setLoadingListener(this);
        //单条目列表展示
        LinearLayoutManager linearLayoutManager=new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        list_view.setLayoutManager(linearLayoutManager);
        //适配器
        xRecyclerViewAdapter = new XRecyclerViewAdapter(this,list);
        list_view.setAdapter(xRecyclerViewAdapter);

        //加载数据(刷新)
        list_view.refresh();
        //pop
        btn_show.set Listener(this);
        View contentView = View.inflate(MainActivity.this, R.layout.pop, null);
        window =new PopupWindow(contentView, StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT, StaggeredGridLayoutManager.LayoutParams.WRAP_CONTENT);
        window.setTouchable(true);
        window.setFocusable(true);
        window.setOutsideTouchable(true);
        window.setBackgroundDrawable(new BitmapDrawable());
        list_pop =  contentView.findViewById(R.id.list_pop);
        grid_pop =  contentView.findViewById(R.id.grid_pop);
        //点击的方法是下面的 
        list_pop.set Listener(this);
        grid_pop.set Listener(this);


        //条目点击事件
        xRecyclerViewAdapter.setonItemClikListener(new Item a() {
            @Override
            public void  Listenter(View view) {

                int childAdapterPosition = xrecyclerView.getChildAdapterPosition(view);
                Goods goods = list.get(childAdapterPosition - 1);
                String detailUrl = goods.getDetailUrl();
                Intent intent=new Intent(MainActivity.this,Main2Activity.class);
                intent.putExtra(\"aaa\",detailUrl);
                Log.i(\"dt------\", detailUrl+\"\");
                startActivity(intent);

            }
        });

        xRecyclerViewAdapter2.setonItemClikListener(new Item a() {
            @Override
            public void  Listenter(View view) {
                int childAdapterPosition = xrecyclerView.getChildAdapterPosition(view);
                Goods goods = list.get(childAdapterPosition - 1);
                String detailUrl = goods.getDetailUrl();
                Intent intent=new Intent(MainActivity.this,Main2Activity.class);
                intent.putExtra(\"aaa\",detailUrl);
                Log.i(\"dt------\", detailUrl+\"\");
                startActivity(intent);

            }
        });
    }


    @Override
    public void  (View v) {

        switch (v.getId()) {
            case R.id.btn_show:
                window.showAsDropDown(btn_show);
                break;
            case R.id.list_pop:
                xrecyclerView.setVisibility(View.GONE);
                list_view.setVisibility(View.VISIBLE);
                Glide.with(this).load(R.drawable.cai1).into(btn_show);
                window.dismiss();
                break;
            case R.id.grid_pop://点击的是按钮
                //隐藏的是main里的列表
                list_view.setVisibility(View.GONE);
                xrecyclerView.setVisibility(View.VISIBLE);
                Glide.with(this).load(R.drawable.cai2).into(btn_show);
                window.dismiss();
                break;
            case R.id.jiage://点击的是按钮
                //隐藏的是main里的列表
                goodsPresenter.requestData(true,2);
                break;

            default:
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        if (requestCode==999){

        }
        super.onActivityResult(requestCode, resultCode, data);
    }


    @Override
    public void success(List<Goods> data) {
        list_view.refreshComplete();
        list_view.loadMoreComplete();
        // 结束刷新的UI
        xrecyclerView.refreshComplete();// 使UI加载完成
        xrecyclerView.loadMoreComplete();// 使UI加载完成
        if (goodsPresenter.isResresh()){// 清空适配器的集合
             xRecyclerViewAdapter.clearList();// 清空集合
        }
        xRecyclerViewAdapter.addAll(data);// 向集合中添加数据
        xRecyclerViewAdapter.notifyDataSetChanged();// 刷新适配器
    }

    @Override
    public void fail(Result result) {
        Toast.makeText(this,\"\"+result.getMsg(),Toast.LENGTH_LONG).show();
        goodsPresenter.unBindCall();
    }

    @Override
    public void onRefresh() {
        goodsPresenter.requestData(true,0);
    }

    @Override
    public void  More() {
    goodsPresenter.requestData(false);
    }

    //解绑
    @Override
    protected void onDestroy() {
        super.onDestroy();
        goodsPresenter.unBindCall();
        goodsPresenter = null;
    }
}

4.main布局

<?  version=\"1.0\" encoding=\"utf-8\"?>
<RelativeLayout  ns:android=\"http://schemas.android.com/apk/res/android\"
     ns:app=\"http://schemas.android.com/apk/res-auto\"
     ns:tools=\"http://schemas.android.com/tools\"
    android:layout_width=\"match_parent\"
    android:layout_height=\"match_parent\"
    tools:context=\".MainActivity\">

    <ImageView
        android:id=\"@+id/btn_back\"
        android:layout_width=\"50dp\"
        android:layout_height=\"50dp\"
        android:layout_alignParentLeft=\"true\"
        android:padding=\"15dp\"
        android:src=\"@drawable/back\"
         />

    <ImageView
        android:id=\"@+id/btn_layout\"
        android:layout_width=\"50dp\"
        android:layout_height=\"50dp\"
        android:layout_alignParentRight=\"true\"
        android:padding=\"15dp\"
        />

    <EditText
        android:id=\"@+id/edit_keywords\"
        android:layout_width=\"match_parent\"
        android:layout_height=\"36dp\"
        android:layout_alignBottom=\"@+id/btn_show\"
        android:layout_marginLeft=\"-38dp\"
        android:layout_marginRight=\"43dp\"
        android:layout_toLeftOf=\"@+id/btn_layout\"
        android:layout_toRightOf=\"@+id/btn_back\"
        android:hint=\"搜索\"
        android:paddingLeft=\"40dp\"
        android:singleLine=\"true\"
        android:text=\"手机\"
        android:textSize=\"16sp\" />
    <ImageButton
        android:id=\"@+id/btn_show\"
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\"
        android:layout_alignParentRight=\"true\"
        android:src=\"@drawable/cai1\"
        android:text=\"列表\" />

    <LinearLayout
        android:id=\"@+id/view\"
        android:layout_width=\"match_parent\"
        android:layout_height=\"wrap_content\"
        android:layout_below=\"@id/btn_show\"
        android:orientation=\"horizontal\">

        <Button
            android:id=\"@+id/zonghe\"
            android:layout_width=\"wrap_content\"
            android:layout_height=\"wrap_content\"
            android:layout_weight=\"1\"
            android:text=\"综合\" />

        <Button
            android:id=\"@+id/xiaoliang\"
            android:layout_width=\"wrap_content\"
            android:layout_height=\"wrap_content\"
            android:layout_weight=\"1\"
            android:text=\"销量\" />

        <Button
            android:id=\"@+id/jiage\"
            android:layout_width=\"wrap_content\"
            android:layout_height=\"wrap_content\"
            android:layout_weight=\"1\"
            android:text=\"价格\" />

        <Button
            android:layout_width=\"wrap_content\"
            android:layout_height=\"wrap_content\"
            android:layout_weight=\"1\"
            android:text=\"筛选\" />
    </LinearLayout>
<!--
    <View

        android:layout_width=\"match_parent\"
        android:layout_height=\"2dp\"

        android:background=\"#cccccc\" />-->

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id=\"@+id/xrecyclerView\"
        android:layout_width=\"match_parent\"
        android:layout_height=\"match_parent\"
        android:layout_below=\"@id/view\"
        android:visibility=\"gone\" />

    <com.jcodecraeer.xrecyclerview.XRecyclerView
        android:id=\"@+id/list_view\"
        android:layout_width=\"match_parent\"
        android:layout_height=\"wrap_content\"
        android:layout_below=\"@id/view\" />
</RelativeLayout>

5. Presenter

package com.example.lenovo.dsweek03.core;


import android.os.Handler;
import android.os.Message;

import com.example.lenovo.dsweek03.bean.Result;

public abstract class  Presenter {
    DataCall dataCall;
    public  Presenter(DataCall dataCall){
        this.dataCall=dataCall;
    }
    Handler handler=new Handler() {
        @Override
        public void handleMessage(Message msg) {
            Result result=(Result)msg.obj;
            if (result.getCode()==0){
                dataCall.success(result.getData());
            }else{
                dataCall.fail(result);
            }

        }
    };
    public void  requestData(final  ... args){
        new Thread(){
            @Override
            public void run() {
                Message message = handler.obtainMessage();
                message.obj=getData(args);
                handler.sendMessage(message);
            }
        }.start();
    }

    protected abstract   getData( [] args);

    //等于空 防止内存溢出
    public void unBindCall(){
        this.dataCall=null;
    }
}

6.Presenter

package com.example.lenovo.dsweek03.presenter;

import com.example.lenovo.dsweek03.bean.Result;
import com.example.lenovo.dsweek03.core. Presenter;
import com.example.lenovo.dsweek03.core.DataCall;
import com.example.lenovo.dsweek03.model.Model;

public class Presenter extends  Presenter {

    public Presenter(DataCall dataCall) {
        super(dataCall);
    }

    @Override
    protected   getData( ... args) {
        Result result = Model.login((String) args[0], (String) args[1]);
        return result;
    }
}

7.Model

package com.example.lenovo.dsweek03.model;

import com.example.lenovo.dsweek03.bean.Result;
import com.example.lenovo.dsweek03.bean.User;
import com.example.lenovo.dsweek03.http.OKHttp;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;

public class Model {

    public static Result login(String mobile,String pwd) {
        String resultString = OKHttp.postForm(\"http://www.zhaoapi.cn/user/login\",
                new String[]{\"mobile\",\"password\"},new String[]{mobile,pwd});
//        String resultString = Utils.get(\"http://www.zhaoapi.cn/user/login\");

        Gson gson=new Gson();
//        Type type = new TypeToken<Result<User>>() {}.getType();
//        new  TypeToken<Result<User>>(){}.getType();
        Type type = new TypeToken<Result<User>>() {}.getType();

        Result result = gson.fromJson(resultString, type);
        return result;
    }
}

8.OKHttp

package com.example.lenovo.dsweek03.http;

import java.io.File;

import okhttp3.FormBody;
import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

public class OKHttp {
public static String get(String s) {
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder().url(s).get().build();
try {
Response response = okHttpClient.newCall(request).execute();

        return response.body().string();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return \"\";
}
public static String postForm(String url,String[] name,String[] value){

    OkHttpClient okHttpClient = new OkHttpClient();

    FormBody.Builder formBuild = new FormBody.Builder();
    for (int i = 0; i < name.length; i++) {
        formBuild.add(name[i],value[i]);
    }

    Request request = new Request.Builder().url(url).post(formBuild.build()).build();

    try {
        Response response = okHttpClient.newCall(request).execute();

        return response.body().string();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return \"\";
}
public static String postFile(String url,String[] name,String[] value,String fileParamName,File file){

    OkHttpClient okHttpClient = new OkHttpClient();

    MultipartBody.Builder requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM);
    if(file != null){
        // MediaType.parse() 里面是上传的文件类型。
        RequestBody body = RequestBody.create(MediaType.parse(\"image/*\"), file);
        String filename = file.getName();
        // 参数分别为: 文件参数名 ,文件名称 , RequestBody
        requestBody.addFormDataPart(fileParamName, \"jpg\", body);
    }
    if (name!=null) {
        for (int i = 0; i < name.length; i++) {
            requestBody.addFormDataPart(name[i], value[i]);
        }
    }

    Request request = new Request.Builder().url(url).post(requestBody.build()).build();

    try {
        Response response = okHttpClient.newCall(request).execute();
        if (response.code()==200) {
            return response.body().string();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return \"\";
}
public static String postJson(String url,String jsonString){

    OkHttpClient okHttpClient = new OkHttpClient();

    RequestBody requestBody = RequestBody.create(MediaType.parse(\"application/json\"),jsonString);

    Request request = new Request.Builder().url(url).post(requestBody).build();

    try {
        Response response = okHttpClient.newCall(request).execute();

        return response.body().string();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return \"\";
}

}

9.DataCall

package com.example.lenovo.dsweek03.core;

import com.example.lenovo.dsweek03.bean.Result;

public interface DataCall<T> {
    void success(T data);
    void fail(Result result);
}

10.Item a

package com.example.lenovo.dsweek03.core;

import android.view.View;

public interface Item a {
    void  Listenter(View view);
}

11.XRecyclerViewAdapter

package com.example.lenovo.dsweek03.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.lenovo.dsweek03.MainActivity;
import com.example.lenovo.dsweek03.R;
import com.example.lenovo.dsweek03.bean.Goods;
import com.example.lenovo.dsweek03.core.Item a;

import java.util.ArrayList;
import java.util.List;

public class XRecyclerViewAdapter extends RecyclerView.Adapter<XRecyclerViewAdapter.MyHolder>{
    Context context;
    List<Goods> list=new ArrayList<>();

    public XRecyclerViewAdapter(Context context, List<Goods> list) {
        this.context = context;
        this.list = list;
    }

    Item a item a;
    public void setonItemClikListener(Item a item ){
        this.item a=item ;
    }
    @NonNull
    @Override
    public XRecyclerViewAdapter.MyHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        //LayoutInflater.from()加载布局 用不了view.inflate
        View view = LayoutInflater.from(context).inflate(R.layout.item_list, viewGroup,false);
        MyHolder myHolder=new MyHolder(view);
        return myHolder;
    }

    @Override
    public void onBindViewHolder(@NonNull final XRecyclerViewAdapter.MyHolder myHolder, int i) {

        /*字符串截取
        String url = dataBeans.get(i).getImages();
        String[] split = url.split(\"\\\\|\");
        if (split.length > 0) {
            Glide.with(context).load(split[0]).into(myHolder.itemIv);
        }
        */


        myHolder.textView1.setText(list.get(i).get ());
        myHolder.textView2.setText(\"¥\"+list.get(i).getPrice());
        String images = list.get(i).getImages();//得到图片集
        String[] split = images.split(\"\\\\|\");//得到一个图片
        if (split.length>0) {
            //将https成http  进行联网显示
            String replace = split[0].replace(\"https\", \"http\");
            Glide.with(context).load(replace).into(myHolder.imageView);//设置图片
        }
        Log.i(\"图片\",list.get(i).get ());

        //条目点击
        myHolder.itemView.set Listener(new View. Listener() {
            @Override
            public void  (View v) {
                item a. Listenter(myHolder.itemView);
            }
        });
    }

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

    public void clearList(){
        list.clear();
    }

    public void addAll(List<Goods> data) {
        if (data!=null){
            list.addAll(data);
        }
    }
//    public static void main(String[] args) {
//        String aa = \"a111a222a333a\";
//        String[] b = aa.split(\"a\");
//        System.out.println(b[0]);
//    }
    public class MyHolder extends RecyclerView.ViewHolder {
        TextView textView1;
        TextView textView2;
        ImageView imageView;
        public MyHolder(@NonNull View itemView) {
            super(itemView);
            // 找控件
            imageView = itemView.findViewById(R.id.img01);
            textView1 = itemView.findViewById(R.id.text1);
            textView2=itemView.findViewById(R.id.text2);

        }
    }
}

12.GoodsModel

package com.example.lenovo.dsweek03.model;

import com.example.lenovo.dsweek03.bean.Goods;
import com.example.lenovo.dsweek03.bean.Result;
import com.example.lenovo.dsweek03.http.OKHttp;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.lang.reflect.Type;
import java.util.List;

public class GoodsModel {
    public static Result goodlist(final String page) {
        String resultString = OKHttp.get(\"http://www.zhaoapi.cn/product/searchProducts?keywords=笔记本&page=\"+page);
        Gson gson=new Gson();
        Type type = new TypeToken<Result<List<Goods>>>() {
        }.getType();
        Result result = gson.fromJson(resultString, type);
        return result;
    }
}

13.GoodsPresenter

package com.example.lenovo.dsweek03.presenter;

import com.example.lenovo.dsweek03.bean.Result;
import com.example.lenovo.dsweek03.core. Presenter;
import com.example.lenovo.dsweek03.core.DataCall;
import com.example.lenovo.dsweek03.model.GoodsModel;

public class GoodsPresenter extends  Presenter {
    private int page=1;
    private boolean isRefresh=true;
//    private int sort=0;

    public GoodsPresenter(DataCall dataCall) {
        super(dataCall);
    }

    @Override
    protected Result getData( ... args) {
        isRefresh=(boolean) args[0];

        if (isRefresh){
            page=1;
//            sort = (int) args[1];
        }else{
            page++;
        }
        Result result=GoodsModel.goodlist(page+\"\");

        return result;
    }
    public boolean isResresh(){
        return isRefresh;
    }
}

14.Main2Activity

package com.example.lenovo.dsweek03;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.webkit.WebChromeClient;
import android.webkit.WebResourceRequest;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Main2Activity extends AppCompatActivity {

WebView mWebView;

@SuppressLint(\" Interface\")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main2);

    mWebView = (WebView) findViewById(R.id.webview);

    /*Intent intent=getIntent();
    String aaa = intent.getStringExtra(\"aaa\");
    mWebView.loadUrl(aaa);*/
   /* WebViewClient client=new WebViewClient();
    mWebView.setWebChromeClient(client);

*/
WebSettings webSettings = mWebView.getSettings();

    // 设置与Js交互的权限
    webSettings.set Enabled(true);
    // 设置允许JS弹窗
    webSettings.set CanOpenWindowsAutomatically(true);

    String url = getIntent().getStringExtra(\"aaa\");
    Log.i(\"dt\", url+\"\");

    //如果不设置WebViewClient,请求会跳转系统浏览器
    mWebView.setWebViewClient(new WebViewClient() {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            //该方法在Build.VERSION_CODES.LOLLIPOP以前有效,从Build.VERSION_CODES.LOLLIPOP起,建议使用shouldOverrideUrlLoading(WebView, WebResourceRequest)} instead
            //返回false,意味着请求过程里,不管有多少次的跳转请求(即新的请求地址),均交给webView自己处理,这也是此方法的默认处理
            //返回true,说明你自己想根据url,做新的跳转,比如在判断url符合条件的情况下
            return false;
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
            //返回false,意味着请求过程里,不管有多少次的跳转请求(即新的请求地址),均交给webView自己处理,这也是此方法的默认处理
            //返回true,说明你自己想根据url,做新的跳转,比如在判断url符合条件的情况下
            return false;
        }
    });

    // 先载入JS代码
    // 格式规定为:file:///android_asset/文件名.html
    mWebView.loadUrl(url);

    // webview只是载体,内容的渲染需要使用webviewChromClient类去实现
    // 通过设置WebChromeClient对象处理 的对话框
    //设置响应js 的Alert()函数
    mWebView.setWebChromeClient(new WebChromeClient());

}

}

15.Main2Activity布局

<?  version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout
    android:orientation=\"vertical\"
     ns:android=\"http://schemas.android.com/apk/res/android\"
     ns:app=\"http://schemas.android.com/apk/res-auto\"
     ns:tools=\"http://schemas.android.com/tools\"
    android:layout_width=\"match_parent\"
    android:layout_height=\"match_parent\"
    tools:context=\".Main2Activity\">
   <WebView
       android:id=\"@+id/webview\"
       android:layout_width=\"match_parent\"
       android:layout_height=\"match_parent\" />
</LinearLayout>

16.列表布局

<?  version=\"1.0\" encoding=\"utf-8\"?>
<LinearLayout  ns: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/img01\"
        android:layout_width=\"150dp\"
        android:layout_height=\"150dp\" />
    <LinearLayout
        android:layout_weight=\"1\"
        android:orientation=\"vertical\"
        android:layout_width=\"wrap_content\"
        android:layout_height=\"wrap_content\">
    <TextView
        android:id=\"@+id/text1\"
        android:layout_width=\"match_parent\"
        android:layout_height=\"100dp\"
        android:text=\"444\"/>

    <TextView
        android:id=\"@+id/text2\"
        android:layout_width=\"match_parent\"
        android:layout_height=\"50dp\"
        android:textColor=\"#ff4040\"
        android:text=\"333\"/>
    </LinearLayout>

</LinearLayout>
收藏 打印