Webview不适合内容

时间:2016-10-13 07:00:48

标签: android webview

我有这个浏览网页浏览器的分页器,当从网络服务加载饼图时,我必须用手指缩小以获得我想要的结果,如何让它在页面上缩小完成?

这是我的代码:

private class CustomPagerAdapter extends PagerAdapter {

    private Context mContext;
    private LayoutInflater mLayoutInflater;
    private ArrayList<GraphItem> charts = new ArrayList<GraphItem>();
    Typeface type = null;

    public CustomPagerAdapter(Context context, ArrayList<GraphItem> charts) {
        mContext = context;
        mLayoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.charts = charts;

        if (MyApplication.lang.equals("en"))
            type = MyApplication.opensanregular;
        else
            type = MyApplication.gdenartwomeduim;
    }

    @Override
    public int getCount() {
        return charts.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == ((LinearLayout) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        View itemView = mLayoutInflater.inflate(R.layout.bar_item, container, false);
        final WebView chartWebView = (WebView) itemView.findViewById(R.id.chartview);
        final TextView topicTitle = (TextView) itemView.findViewById(R.id.topicTitle);
        final ImageView ivIndicator = (ImageView) itemView.findViewById(R.id.ivIndicator);
        final RelativeLayout titlelayout=(RelativeLayout) itemView.findViewById(R.id.titlelayout);
        if(MyApplication.lang.equals("ar")) {
            titlelayout.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
            topicTitle.setTypeface(MyApplication.gdenarBold);
        }
        Picasso.with(CountryProfileActivity.this)
                .load(charts.get(position).getMobileIconURL())
                //.placeholder(R.mipmap.icon)
                //.resize(250,200)
                //.rotate(90)
                .into(ivIndicator);
        topicTitle.setVisibility(View.VISIBLE);
        topicTitle.setTypeface(type);
        chartWebView.getSettings().setJavaScriptEnabled(true);
        chartWebView.getSettings().setAllowFileAccess(true);
        chartWebView.getSettings().setAllowContentAccess(true);
        chartWebView.getSettings().setLoadWithOverviewMode(true);
        chartWebView.getSettings().setUseWideViewPort(true);;
        chartWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
        //wvReport.addJavascriptInterface(new JavaScriptInterface(this), "Android");

        chartWebView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
                if (MyApplication.lang.equals("ar"))
                    topicTitle.setText(charts.get(position).getTopicTitleAr());
                else
                    topicTitle.setText(charts.get(position).getTopicTitleEn());
            }
        });

        chartWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int progress) {

            }

            @Override
            public void onReceivedTitle(WebView view, String title) {

            }
        });
        //wvReport.loadUrl(url);

        if (MyApplication.lang.equals("en")) {
            topicTitle.setTypeface(MyApplication.opensansBol);
            chartWebView.loadDataWithBaseURL("file:///android_asset/", "<html><head>\n" +
                    "<style type=\"text/css\">\n" +
                    "@font-face {\n" +
                    "    font-family: MyFont;\n" +
                    "    src: url(\"file:///android_asset/OpenSans-Regular.ttf\")\n" +
                    "}\n" +
                    "body {\n" +
                    "    font-family: MyFont;\n" +
                    "    text-align: justify;\n" +
                    "}\n" +
                    "</style><body>" + charts.get(position).getPieChart() + "</body></html>", "text/html", "UTF-8", "");
        }else{
            chartWebView.loadDataWithBaseURL("file:///android_asset/", "<html><head>\n" +
                    "<style type=\"text/css\">\n" +
                    "@font-face {\n" +
                    "    font-family: MyFont;\n" +
                    "    src: url(\"file:///android_asset/GE_Dinar_Two_Medium.otf\")\n" +
                    "}\n" +
                    "body {\n" +
                    "    font-family: MyFont;\n" +
                    "    text-align: justify;\n" +
                    "}\n" +
                    "</style><body>" + charts.get(position).getPieChart() + "</body></html>", "text/html", "UTF-8", "");
        }


        container.addView(itemView);
        chartWebView.setBackgroundColor(0);

        return itemView;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((LinearLayout) object);
    }
}

这是不使用视口的图像

No port

这是带端口的图像(它变得非常小)

With port

这是用手指缩小(我想要的结果)

enter image description here

0 个答案:

没有答案